Posts

How to create Pop-Up Dialog Animation in App | Android App Development | Java

Image
 In this post, you will learn how to create Pop-Up animation for Dialog Box in your Android Application. A dialog is a small window that prompts the user to make decision or enter additional information. A dialog is normally used for modal events that require users to take an action before they can proceed. Implementation: First, create a new Android Resource Directory of type 'anim'. In it create two anim files 'scale_up.xml' and 'scale_down.xml'. These files will contain the code for our dialog animation. In the scale_up.xml file, add the following code: And in the scale_down.xml file, add the following code: Create a new style and add these two xml files to it. Now add a button in the activity_main.xml file which will instantiate the pop-up dialog.   Now create a new layout file which will contain the design layout of the dialog box .Add the following code to it.  Finally, in the MainActivity.java class, setup the dialog box  like so... Output :

How to check internet availability in app | Android App Development | Java

 In this post, you will learn how to check the internet availability access in your application. Checking the internet access is important when working with API's, fetching or uploading data from servers etc... Implementation: First, in the activity_main.xml file, add the following code: Then, create a new activity (NewActivity), and in its xml file (activity_new.xml), add the following code: Now in the MainActivity.java file, add the onClickListener to the button to navigate to the NewActivity. To do this, add the following code: After this, create a new Java class to check the network state. In this class (CheckNetwork.java), add the following code: Now, in the NewActivity.java file, add the following code: Finally, add the Internet and Access Network State permissions in the AndroidManifest.xml file And that's it...Now try running your app. To learn more about reading the Network States in Android, refer this : https://developer.android.com/training/basics/network-ops/read

How to play Audio on Button Click in app | Android App Development | Java

 In this post, you will learn how to play audio on button click feature in your Android App. We will be using the MediaPlayer to implement this functionality. MediaPlayer class can be used to control playback of audio/video files and streams. MediaPlayer is not thread-safe. Creation of and all access to player instances should be on the same thread. If registering  c allbacks, the thread must have a Looper. Implementation: First, in the activity_main.xml file, add the following code: Then, create a new Android Resources Directory of type ' raw ' and add the audio sounds of your choice in it. Then in the MainActivity.java file, add the following code: Output:

How to implement simple Pie Chart in app | Android Studio | Java | Android App Development

Image
In this post, you will learn how to implement Pie Chart in you Android Application with Java. What is Pie Chart and what are its uses ? Pie charts are used in data handling and are circular charts divided up into segments which each represent a value. Pie charts are divided into sections (or 'slices') to represent values of different sizes. Pie charts are a visual device to help us understand data more easily. Implementation: First, add the dependency for Pie Chart in build.gradle(Module: app) with latest version. implementation 'com.github.blackfizz:eazegraph:1.2.5l@aar' implementation 'com.nineoldandroids:library:2.4.0' Now, in the activity_main.xml file, add the following code: Now, in the MainActivity.java file, add the following code: (make sure to include your package name while copying the code) Output:

Builduing a Simple Flashlight App in Android Studio

Image
 In this post, you will learn how to create a simple flashlight app to enable or disable the phone's flashlight in android stuido using Java.     For building the app, first, create a new project and add the power icon from vector assets in your drawable folder. Now, create two new drawable resource files that will be the background for our switch on and switch off button. Add the following code to the files: Code for switch on button: Code for switch off button: Once this is done, in the activity_main.xml file, create the layout for the app screen. Add the following code: The background of the image buttons are the switch_on and switch_off drawable files that we created earlier. Now, in the MainActivity.java class , add the following code: Here the Camera used is Camera (android.hardware) and not the graphics one. Now finally, in the AndroidManifest.xml file, add the permissions to allow access to the device's  camera. <uses-permission android:name="android.permission

ViewPager2 tutorial for Beginners: Android

  In this post you will learn how to implement ViewPager2 in your android app using Java. What is the use of ViewPager? Adding a ViewPager to the application UI allow the users to swipe forward and backward between views in the app. eg. A photo gallery app in which the users can swipe the images forward and backward. Implementing the ViewPager: First, add the dependency for ViewPager2 in the build.gradle(Module: app) with the latest version: implementation "androidx.viewpager2:viewpager2:1.0.0" Now , in the activity_main.xml file, add the following code: After that, create a new Java class that will be the Model class for the items to be displayed in the view .Add the following code: Now create a new layout resource file that will define the structure of individual view of our ViewPager. Add the code to it: Once this is done, create another Java class that will be the adapter for our ViewPager. An adapter basically binds the items to the respective views in the app. Add the f

Multiplication Tables Android App

Image
In this post, we will be demonstrating how to create a simple multiplication tables app using Android Studio in Java. We will be using a ListView to display the multiplication table of a number entered by the user. ListView -   ListView in Android is a view which contains the group of items and display them in a scrollable list. ListView is a default scrollable which does not user other scroll view. Now that we know what a ListView is, lets begin making the app. For this, we will require an EditText where in the user can input a number, a Button and a ListView which will display the multiplication table of the number entered by the user. In the activity_main.xml file , write the code as follows: Now in the MainActivity,java file , when the user clicks the button, we will call the fillList() methodt that will populate our ListView with the multiplication table. Write the code as follows: We will need to create an an xml file that will define the structure of how the elements in the List