Android – change dialog button position

Can I change the position of the button on the dialog box to the outside of the dialog box itself? Something like this (the Red Square is the button):

I know I can get buttons in the following ways:

 dialog.getButton(AlertDialog.BUTTON_NEGATIVE)

But I can't find a way to change its position in the manual

resolvent:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:padding="20dp"
android:background="#00000000">

<LinearLayout
    android:background="@drawable/border_background"
    android:layout_gravity="center"
    android:gravity="center"
    android:padding="20dp"
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:orientation="vertical">

    <TextView
        android:layout_width="250dp"
        android:layout_height="wrap_content"
        android:text="@string/update_app"
        android:textSize="18sp"
        android:textColor="@color/white"
        android:layout_gravity="center_horizontal"
        android:gravity="center" />

</LinearLayout>
<Button
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:layout_marginTop="20dp"
    android:background="#123456"
    android:layout_width="wrap_content"
    android:layout_height="35dp"
    android:layout_gravity="center"
    android:gravity="center"
    android:textColor="#ffffff"
    android:textSize="14sp"
    android:onClick="onUpdateClicked"
    android:text="Button" />

Instead of using the default alarm dialog box, make a custom layout similar to my layout here and click the button to perform the required actions

You can call n to display this layout without expanding like this. Edit: 1

 public void showUpdateLayout() {
    mParentView = (ViewGroup) findViewById(android.R.id.content);
    if (mParentView != null) {
        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
        mUpdateLayout = inflater.inflate(R.layout.upadte_layout, mParentView, false);
        mParentView.addView(mUpdateLayout);
        if (mUpdateLayout != null) {
            mUpdateLayout.setVisibility(View.VISIBLE);
        }
    }

Write this method in ur public class (or custom aprent activity). Call this method when you need a reminder

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>