Android-更改对话框按钮的位置 [英] Android - change dialog button location
问题描述
是否可以将对话框上按钮的位置更改为对话框本身之外的位置?像这样的东西(红色方块是按钮):
Is it possible to change the location of the button on the dialog to the outside of the dialog itself? something like this (the red squares are buttons):
我知道我可以使用以下按钮:
I know I can get the button with :
dialog.getButton(AlertDialog.BUTTON_NEGATIVE)
但是我在手册中找不到更改位置的方法.
but I couldn't find on the manual the way to change it's location.
推荐答案
<?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 default alert dialog, make a custom layout something like my layout here. And perform desired action on button.
您可以调用n显示此布局而不会像这样夸大. 1
You can call n show this layout without inflating like this. 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);
}
}
在您的公共班级(或自定义Apent活动)中编写此方法.并在需要提醒时调用此方法.
Write this method in ur public Class (or Custom Aprent Activity). and call this method when u need to alert.
这篇关于Android-更改对话框按钮的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!