Posts

Showing posts with the label Android Studio

How to surf trough screens using screen timeout

Assume you have two activities First Activity and Second Activity. To go to the second activity from the first activity without tapping add the below code into the 'onCreate' class in the activity. Here we use the android Handler getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);new android.os.Handler().postDelayed(new Runnable() { @Override public void run() { Intent i1 = new Intent(FirstActivity.this, SecondActivity.class); startActivity(i1); } }, 3000); According to the above code the time it takes to go to the next screen it takes 3 seconds (3000 milli seconds)

Adding app bar to a single activity when it is removed from the styles.xml file

Add the following code into the .xml file <android.support.v7.widget.Toolbar android:id="@+id/my_toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="?attr/colorPrimary" android:elevation="4dp" android:theme="@style/ThemeOverlay.AppCompat.ActionBar" app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/> If you want to add a text into the app bar then add the following code into the onCreate class of the relevant activity. Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar); setSupportActionBar(myToolbar);

Using buttons in Android

Screen change using buttons Create two activities. Here I'm using MainActivity(1st Screen) and the FunctionActivity(2nd Screen). Add a button to the splash activity layout and give a method name to the onClick action. <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Function" android:id="@+id/button3" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:width="150dp" android:onClick="fdemo"/> </Button> Then write the following method in the MainActivity public void fdemo (View v){ Intent i= new Intent(MainActivity.this, Function.class); startActivity(i); } Adding About message button(Using toast) Add a button to the  activity layout  and give a method name to the onClick action <Button android:layout_width="wrap_conte...

Creating a simple application using Android Studio

Image
When you open the Android Studio the following screen will be prompted Select "Start a new Android Studio Project" Give a name to your project and click 'Next' Here you can choose the least version of android in  which your app can run. Then click 'Next' Select "Empty Activity" and click 'Next' Here you can give the "Activity Name"(Leave the 'Activity' part in your name) Then click 'Finish'