Found 1631 Articles for Android

How to verify enter number is phone number or not using regex in android?

Chandu yadav
Updated on 30-Jul-2019 22:30:24

2K+ Views

This example demonstrates how to verify enter number is phone number or not, using regex in android.Step 1 - Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 - Add the following code to res/layout/activity_main.xml.         In the above code, we have taken Edit text and text view. when the user clicks on text view, it will take data from edit text and valid the data.Step 3 - Add the following code to src/MainActivity.javapackage com.example.andy.myapplication; import android.os.Build; import android.os.Bundle; import android.support.annotation.RequiresApi; ... Read More

How to remove shadow below action bar in Android?

Arjun Thakur
Updated on 30-Jul-2019 22:30:24

1K+ Views

By default, android provides shadow for action bar. This example demonstrates How to remove shadow below the action bar.Step 1 - Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 - Add the following code to res/layout/activity_main.xml.     Step 3 - Add the following code to src/MainActivity.javapackage com.example.andy.myapplication; import android.os.Build; import android.os.Bundle; import android.support.annotation.RequiresApi; import android.support.v7.app.AppCompatActivity; import android.widget.TextView; public class MainActivity extends AppCompatActivity {    int view = R.layout.activity_main;    TextView text;    @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)    @Override    protected void onCreate(Bundle savedInstanceState) ... Read More

How to make back button twice to close an activity in Android?

Ankith Reddy
Updated on 30-Jul-2019 22:30:24

675 Views

Sometimes we click back button unintentionally, When you click on a back button it will close your application or will go back to another activity. To avoid this problem, This example demonstrates how to make back button twice to close an activity.Step 1 - Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 - Add the following code to res/layout/activity_main.xml.     Step 3 - Add the following code to src/MainActivity.javapackage com.example.andy.myapplication; import android.app.ActivityManager; import android.content.Context; import android.content.Intent; import android.os.Build; import android.os.Bundle; import android.os.VibrationEffect; ... Read More

How to make a smooth image rotation in Android?

Ankith Reddy
Updated on 30-Jul-2019 22:30:24

1K+ Views

This example demonstrates how to make a smooth image rotation in Android.Step 1 - Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 - Add the following code to res/layout/activity_main.xml.         In the above code, we have taken a text view and image view. When you click on text view, Image will get rotate in anti clock direction.Step 3 - Add the following code to src/MainActivity.javapackage com.example.andy.myapplication; import android.os.Build; import android.os.Bundle; import android.support.annotation.RequiresApi; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.view.animation.Animation; import android.view.animation.LinearInterpolator; ... Read More

How to get battery level and state in Android?

Arjun Thakur
Updated on 30-Jul-2019 22:30:24

1K+ Views

This example demonstrates how to get battery level and state in Android.Step 1 - Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 - Add the following code to res/layout/activity_main.xml.     In the above code, we have taken a text view. it contains battery percentage.Step 3 - Add the following code to src/MainActivity.javapackage com.example.andy.myapplication; import android.os.BatteryManager; import android.os.Build; import android.os.Bundle; import android.support.annotation.RequiresApi; import android.support.v7.app.AppCompatActivity; import android.widget.TextView; public class MainActivity extends AppCompatActivity {    int view = R.layout.activity_main;    TextView text;    @RequiresApi(api = ... Read More

How to Counting Chars in EditText Changed Listener in Android?

Chandu yadav
Updated on 30-Jul-2019 22:30:24

840 Views

Some situations, we have to restrict an edit text for some characters. To solve this situation, in this example demonstrate how to Counting Chars in Edit Text Changed Listener.Step 1 - Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 - Add the following code to res/layout/activity_main.xml.     In the above code, we have taken one edit text. It going to check the length of the entered characters, if it exceeds 5 then it shows an error message.Step 3 - Add the following ... Read More

How to check if android application is running background?

George John
Updated on 30-Jul-2019 22:30:24

2K+ Views

There are so many situations, that we should find android application is running background or not. This example demonstrates how to check if an android application is running background.Step 1 - Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 - Add the following code to res/layout/activity_main.xml.     In the above layout, it contains text view, when the application is in foreground mode, it shows text view else you will get information in a log.Step 3 - Add the following code to src/MainActivity.javapackage ... Read More

How to change position of Toast in Android?

Ankith Reddy
Updated on 30-Jul-2019 22:30:24

2K+ Views

Before getting into an example, we should know what is toast in android. Toast is subclass for  java.lang.Object and used to show a short message for a short period of time after that is going to disappear.This example demonstrates how to change the position of Toast in Android.Step 1 - Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 - Add the following code to res/layout/activity_main.xml.     In the above code, we have taken a text view. when the user clicks on text ... Read More

How do I make a dotted/dashed line in Android?

Arjun Thakur
Updated on 30-Jul-2019 22:30:24

3K+ Views

This example demonstrates how do I make a dotted/dashed line in Android.Step 1 - Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 - Add the following code to res/layout/activity_main.xml.         In the above code, we have text view with image view. Image view contains a dotted background. So create dotted.xml in drawable as shown below -             Step 3 - Add the following code to src/MainActivity.javapackage com.example.andy.myapplication; import android.os.Build; import android.os.Bundle; import android.support.annotation.RequiresApi; import ... Read More

Can an Android Toast be longer than Toast.LENGTH_LONG?

Chandu yadav
Updated on 30-Jul-2019 22:30:24

151 Views

Sometimes we need to display more time then LENGTH_LONG. This example demonstrates how to show toast longer than Toast.LENGTH_LONG.Step 1 - Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 - Add the following code to res/layout/activity_main.xml.     In the above code, we have taken a text view. when a user clicks on text view, it will show toast for 1000 ms.Step 3 - Add the following code to src/MainActivity.javapackage com.example.andy.myapplication; import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.support.annotation.RequiresApi; import android.support.v7.app.AppCompatActivity; import android.view.Gravity; ... Read More

Advertisements