Found 1631 Articles for Android

How to fix android.os.NetworkOnMainThreadException?

Azhar
Updated on 03-Jul-2020 13:11:21

2K+ 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

Android, How to crop circular area from bitmap

Azhar
Updated on 03-Jul-2020 13:13:37

923 Views

This example demonstrates how to crop circular area from bitmap 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.medkart.sample; import androidx.appcompat.app.AppCompatActivity; import android.content.Context; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.PorterDuff; import android.graphics.PorterDuffXfermode; import android.graphics.Rect; import android.graphics.RectF; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.ImageView; import android.widget.RelativeLayout; public class MainActivity extends AppCompatActivity ... Read More

How to crop circular area from bitmap in Android?

Azhar
Updated on 03-Jul-2020 12:53:52

135 Views

This example demonstrates how do I crop circular area from bitmap 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.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Path; import android.graphics.PorterDuff; import android.graphics.PorterDuffXfermode; import android.os.Bundle; import android.view.MotionEvent; import android.view.View; public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);   ... Read More

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

Azhar
Updated on 03-Jul-2020 12:54:26

2K+ 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 to add a border to the top and bottom of an Android View?

Azhar
Updated on 03-Jul-2020 12:55:12

6K+ 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 get Resource name using Resource id in Android?

Azhar
Updated on 03-Jul-2020 12:55:54

868 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 can I create a table with borders in Android?

Azhar
Updated on 03-Jul-2020 12:56:33

2K+ 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 convert Bitmap to drawable in Android?

Azhar
Updated on 03-Jul-2020 12:57:08

2K+ Views

This example demonstrates how do I convert Bitmap to drawable 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.graphics.Bitmap; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.ImageView; public class MainActivity extends AppCompatActivity {    ImageView imageView;    Button button;    Bitmap bitmap;    Drawable drawable;    @Override    protected void onCreate(Bundle savedInstanceState) {   ... Read More

How to Set opacity for View in Android?

Azhar
Updated on 03-Jul-2020 12:57:43

2K+ 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 add an image on EditText in Android?

Azhar
Updated on 03-Jul-2020 12:58:36

1K+ Views

This example demonstrates how add an image on 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/MainAvtivity.javapackage com.example.sample; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);    } }Step 4  − Add the following code to drawable/background.xml         ... Read More

Advertisements