Android Articles

Page 30 of 125

How to fix android.os.NetworkOnMainThreadException?

Azhar
Azhar
Updated on 03-Jul-2020 3K+ Views

The exception that is thrown when an application attempts to perform a networking operation on its main thread.This is only thrown for applications targeting the Honeycomb SDK or higher. Applications targeting earlier SDK versions are allowed to do networking on their main event loop threads, but it's heavily discouraged.Kindly refer the below example program to fix this exception −This example demonstrates how do I fix the android.os.NetworkOnMainThreadException.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.   ...

Read More

How to open Facebook page from Android app?

Azhar
Azhar
Updated on 03-Jul-2020 2K+ Views

This example demonstrates about How to open Facebook page from 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/MainActivity.javapackage app.com.sample; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.view.View; import androidx.appcompat.app.AppCompatActivity; public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);    }    public void fbClick(View view) {     ...

Read More

How to Set opacity for View in Android?

Azhar
Azhar
Updated on 03-Jul-2020 3K+ Views

This example demonstrates how to Set opacity for View 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.animation.ObjectAnimator; import android.app.Activity; import android.view.View; import android.widget.Button; import android.widget.TextView; public class MainActivity extends AppCompatActivity {    TextView txt;    Button btn;    ObjectAnimator objectanimator;    @Override    protected void onCreate(Bundle savedInstanceState) {       ...

Read More

How can I create a table with borders in Android?

Azhar
Azhar
Updated on 03-Jul-2020 3K+ Views

This example demonstrates how create a table with borders 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.                                                                                         ...

Read More

How to get Resource name using Resource id in Android?

Azhar
Azhar
Updated on 03-Jul-2020 1K+ Views

This example demonstrates how do I get resource name using Resource id 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.widget.TextView; public class MainActivity extends AppCompatActivity {    TextView textView;    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       textView = findViewById(R.id.textView);       int text ...

Read More

How to add a border to the top and bottom of an Android View?

Azhar
Azhar
Updated on 03-Jul-2020 7K+ Views

This example demonstrates how to add a border to the top and bottom of an Android View .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/drawable/border_top_bottom.xml                                                                       Step 3  − Add the following code to res/layout/top_bottom_border_in_android_view.xml ...

Read More

How to disable the click of home button of Android device?

Azhar
Azhar
Updated on 03-Jul-2020 3K+ Views

This example demonstrates how to disable the click of home button of Android device .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.medkart.sample; import androidx.appcompat.app.AppCompatActivity; import android.app.ActivityManager; import android.content.Context; import android.os.Bundle; public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);    }    @Override    protected void onPause() { ...

Read More

How do I create a splash screen on Android App?

Azhar
Azhar
Updated on 03-Jul-2020 892 Views

This example demonstrates how to pass data between activities.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.content.Intent; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import static java.lang.Thread.sleep; public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       startActivity(new Intent(MainActivity.this, SecondActivity.class));       try {          sleep(3000);     ...

Read More

How can I set an icon for my Android application?

Azhar
Azhar
Updated on 03-Jul-2020 4K+ Views

This example demonstrates how set an icon for my Android application .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  − Further follow the path to reach the desired folder to add icon (app → res → mipmap).Step 3 - Add you app icon. You can just simply copy and paste the image in mipmap folder.Step 4 - After placing the image in the mipmap folder. You need to rename the default icon name to your icon image name.Step 5  − Add the following ...

Read More

How to change the position of the dialog on Screen android?

Azhar
Azhar
Updated on 03-Jul-2020 2K+ Views

This example demonstrates how do I change the position of the dialog on Screen 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.AlertDialog; import android.content.DialogInterface; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.Gravity; public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       AlertDialog.Builder builder = new AlertDialog.Builder(this);     ...

Read More
Showing 291–300 of 1,250 articles
« Prev 1 28 29 30 31 32 125 Next »
Advertisements