Android example - Change AlertDialog background color

Android example - Change AlertDialog background color - Hello friend inabnomaniiyaha, In the article that you read this time with the title Android example - Change AlertDialog background color, we have prepared this article well for you to read and take information in it. hopefully the contents of the post Artikel android-example,what we write you can understand. Alright, happy reading.

Judul : Android example - Change AlertDialog background color
link : Android example - Change AlertDialog background color

Baca juga


Android example - Change AlertDialog background color

Change AlertDialog background color

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>

<android.support.design.widget.CoordinatorLayout

    xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:app="http://schemas.android.com/apk/res-auto"

    android:id="@+id/coordinator_layout"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:background="#a3baa5"

    >

    <Button

        android:id="@+id/btn_alert"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="Show Alert Dialog"

        android:layout_gravity="center"

        />

</android.support.design.widget.CoordinatorLayout>

MainActivity.java

public class MainActivity extends AppCompatActivity {

    private Context mContext;

    private Activity mActivity;

    private CoordinatorLayout mCLayout;

    private Button mButton;

    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);


        // Get the application context

        mContext = getApplicationContext();

        mActivity = MainActivity.this;


        // Get the widget reference from XML layout

        mCLayout = (CoordinatorLayout) findViewById(R.id.coordinator_layout);

        mButton = (Button) findViewById(R.id.btn_alert);


        // Set a click listener for the button widget

        mButton.setOnClickListener(new View.OnClickListener() {

            @Override

            public void onClick(View view) {

                // Initializing a new alert dialog

                AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);


                // Set a title for alert dialog

                builder.setTitle("Say Hello!");


                // Show a message on alert dialog

                builder.setMessage("Are you want to do this?");


                // Set the positive button

                builder.setPositiveButton("Say",null);


                // Set the negative button

                builder.setNegativeButton("Not now", null);


                // Create the alert dialog

                AlertDialog dialog = builder.create();


                // Finally, display the alert dialog

                dialog.show();

        });

    }

}

Change AlertDialog background color



That's the article Android example - Change AlertDialog background color

That's it for the article Android example - Change AlertDialog background color this time, hopefully can be useful for all of you. well, see you in another article post.

You are now reading the article Android example - Change AlertDialog background color with link addresshttps://inabnonapudyawanabing.blogspot.com/2021/03/android-example-change-alertdialog.html

Related Posts :

0 Response to " Android example - Change AlertDialog background color"

Post a Comment

Tips Tricks for Android Phone

Tips & Tricks for Android Phone is a free android app and Collection of Tips and Tricks related to using your android mobile device lik...