How to support different screen size in Android?

Azhar
Updated on 26-Nov-2019 08:12:25

1K+ Views

This example demonstrates how to support different screen sizes 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.app.sample; import androidx.appcompat.app.AppCompatActivity; import android.util.DisplayMetrics; import android.widget.TextView; import android.os.Bundle; public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       DisplayMetrics metrics = new DisplayMetrics();       ... Read More

How to write a SoftKeyboard open and close listener in an activity in Android?

Azhar
Updated on 26-Nov-2019 08:08:50

1K+ Views

This example demonstrates how to write a SoftKeyboard open and a close listener in activity 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.app.sample; import androidx.annotation.RequiresApi; import androidx.appcompat.app.AppCompatActivity; import androidx.constraintlayout.widget.ConstraintLayout; import android.os.Bundle; import android.graphics.Rect; import android.os.Build; import android.view.View; import android.view.ViewTreeObserver; import android.view.inputmethod.InputMethodManager; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; public class MainActivity extends AppCompatActivity implements View.OnClickListener{    ConstraintLayout ... Read More

How to add jar as library on Android Studio?

Azhar
Updated on 26-Nov-2019 08:05:08

1K+ Views

This example demonstrates how to add jar as a library on Android Studio.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 jar file to Project/app/libs/Step 3 − Add the following dependencies to File/Project StructureStep 4 − Add the following code to res/layout/activity_main.xml.     Step 5 − Add the following code to src/MainActivity.javapackage com.app.sample; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);     ... Read More

How to send Email on Android using JavaMail API?

Azhar
Updated on 26-Nov-2019 07:57:24

2K+ Views

This example demonstrates how to send Email on Android using JavaMail API.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.app.sample; import androidx.appcompat.app.AppCompatActivity; import android.view.View; import android.widget.Button; import android.widget.EditText; import java.util.Properties; import javax.mail.PasswordAuthentication; import javax.mail.Session; import android.os.Bundle; public class MainActivity extends AppCompatActivity implements View.OnClickListener {    private EditText editTextEmail;    private ... Read More

How to disable copy/paste from/to EditText in Android App?

Azhar
Updated on 26-Nov-2019 07:49:25

699 Views

This example demonstrates how do I disable copy/paste from/to editText 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 androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.view.ActionMode; import android.view.Menu; import android.view.MenuItem; import android.widget.EditText; public class MainActivity extends AppCompatActivity {    EditText editText;    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       editText = ... Read More

How to find out if the GPS of an Android device is enabled or not?

Azhar
Updated on 26-Nov-2019 07:46:30

194 Views

This example demonstrates how do I find out if the GPS of an Android device is enabled or not.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 androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; import android.content.DialogInterface; import android.content.Intent; import android.location.LocationManager; import android.os.Bundle; import android.widget.Toast; import java.util.Objects; public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       ... Read More

How to listen for a WebView finishing loading a URL in Android?

Azhar
Updated on 26-Nov-2019 07:41:34

3K+ Views

This example demonstrates how do I listen for a webview finishing loading a 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 androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.Button; import android.widget.TextView; import android.widget.Toast; public class MainActivity extends AppCompatActivity {    WebView webView;    TextView textView;    Button btnLoad;    @Override    protected void ... Read More

How to quit application programmatically?

Azhar
Updated on 26-Nov-2019 07:36:08

3K+ Views

This example demonstrates how do I quit application programmatically 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 androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.view.View; public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);    }    public void QuitApp(View view) {       MainActivity.this.finish();       ... Read More

How to display animated gif images in Android?

Azhar
Updated on 26-Nov-2019 07:33:23

3K+ Views

This example demonstrates how do I display animated gif images 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.Add the following dependency in build.gradle: Module: appimplementation 'com.github.bumptech.glide:glide:4.9.0'Step 2 − Add the following code to res/layout/activity_main.xml.         Step 3 − Add the following code to src/MainActivity.javaimport androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.ImageView; import com.bumptech.glide.Glide; public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);    } ... Read More

How to create a multilevel ListView in an Android app?

Azhar
Updated on 26-Nov-2019 07:30:45

409 Views

This example demonstrates how do I create a multilevel listView 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 androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.ExpandableListAdapter; import android.widget.ExpandableListView; import android.widget.Toast; import java.util.ArrayList; import java.util.HashMap; import java.util.List; public class MainActivity extends AppCompatActivity {    ExpandableListView expandableListView;    ExpandableListAdapter expandableListAdapter;    ListexpandableListTitle;    HashMap expandableListDetail;    @Override    protected void onCreate(Bundle savedInstanceState) {   ... Read More

Advertisements