Remove Button or Make It Invisible in Android

Azhar
Updated on 03-Jul-2020 07:14:01

1K+ Views

This example demonstrates how remove a button or make it invisible 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.               Step 3 − Add the following code to src/MainActivity.javapackage com.example.sample; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.app.Activity; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class MainActivity extends AppCompatActivity {    OnClickListener listener1=null;    OnClickListener listener2=null;    Button button1;    Button button2;    @Override    protected void onCreate(Bundle ... Read More

Display Toast in Android

Azhar
Updated on 03-Jul-2020 07:10:11

1K+ Views

This example demonstrates how to display Toast in Android.Step 1 − Create a new project in Android Studio, go to File rArr; 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.sample; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.Toast; public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       //Displaying Toast with Hello World message       Toast.makeText(getApplicationContext(), "Hello World", Toast.LENGTH_SHORT).show();   ... Read More

Load and Display an Image in ImageView on Android App

Azhar
Updated on 03-Jul-2020 07:01:48

4K+ Views

This example demonstrates how to load and display an image in ImageView on Android App.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/MyAndroidAppActivity.javapackage com.example.sample; import android.support.v7.app.AppCompatActivity; import android.app.Activity; import android.os.Bundle; import android.widget.Button; import android.widget.ImageView; import android.view.View; import android.view.View.OnClickListener; public class MyAndroidAppActivity extends AppCompatActivity {    Button button;    ImageView image;    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState); ... Read More

Display Custom View in ActionBar in Android

Azhar
Updated on 03-Jul-2020 07:01:08

802 Views

This example demonstrates how to display custom view in ActionBar 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.     Step 3 − Add the following code to res/layout/custom_action_bar.xml.                                         Step 4 − Add the following code to src/MainActivity.javapackage com.example.sample; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.support.v7.app.ActionBar; import android.view.View; import ... Read More

Create EditText with Rounded Corners in Android

Azhar
Updated on 03-Jul-2020 07:00:11

9K+ Views

This example demonstrates how to create EditText with rounded corners 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.     Step 3 − Create a drawable resource file and Add the following code to drawable/et_style.xml         Step 4   − Add the following code to src/MainActivity.javapackage com.example.sample; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.EditText; public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {       ... Read More

Get Android Device Screen Height and Width

Azhar
Updated on 03-Jul-2020 06:49:03

1K+ Views

This example demonstrates how do I get android device screen height, width.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.javaimport android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.DisplayMetrics; import android.widget.TextView; public class MainActivity extends AppCompatActivity {    TextView height, width, inches;    DisplayMetrics displayMetrics;    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);     ... Read More

Download and Save Image from URL in Android

Azhar
Updated on 03-Jul-2020 06:48:26

3K+ Views

This example demonstrates how do I download and save an image from a given URL 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.         Step 3 − Add the following code to src/MainActivity.javaimport android.app.Activity; import android.app.ProgressDialog; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.AsyncTask; import android.support.design.widget.CoordinatorLayout; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.ImageView; import android.widget.Toast; import java.io.BufferedInputStream; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.MalformedURLException; import ... Read More

Put ListView into ScrollView Without Collapsing on Android

Azhar
Updated on 03-Jul-2020 06:47:44

3K+ Views

This example demonstrates how to put a ListView into a ScrollView without it collapsing on 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.                     Step 3 − Add the following code to src/MainActivity.javapackage com.example.sample; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.ArrayAdapter; import android.widget.ListView; public class MainActivity extends AppCompatActivity {    private String listview_array[]={ "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE", "TEN" ... Read More

Start Service Using Alarm Manager in Android

Azhar
Updated on 03-Jul-2020 06:44:23

2K+ Views

This example demonstrates how do I start a service using alarm manager 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.         Step 3 − Add the following code to src/MainActivity.javapackage app.com.sample; import android.app.AlarmManager; import android.app.PendingIntent; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.Toast; import java.util.Calendar; public class MainActivity extends AppCompatActivity {    Button btnStart, btnStop;    PendingIntent pendingIntent;    @Override    protected void onCreate(Bundle savedInstanceState) ... Read More

Add and Remove Views in Android Dynamically

Azhar
Updated on 03-Jul-2020 06:43:35

4K+ Views

This example demonstrates how to Add and Remove Views in Android Dynamically.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 2 − Add the following code to res/layout/field.xml             Step 3 − Add the following code to res/values/strings.xml    Sample           Mobile       ... Read More

Advertisements