我在android xml文件中有一个警告对话框。我的警告对话框左侧有一个图标。我想将图标的位置改为右侧。我也不想使用custum对话框
像这样 :
a)如果你在对话框标题(TextView)中将它作为drawable,只需使用drawableRight
android:drawableRight="@drawable/yourIcon"
b)如果它是RelativeLayout中的ImageView / ImageButton,请使用alignParentRight
android:layout_alignParentRight="true"
c)如果它是LinearLayout中的ImageView / ImageButton,则将其放在TextView之后
<LinearLayout
android:layout_width="300dp"
android:layout_height="300dp">
<TextView
android:text="some text"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageView
android:src="@drawable/yourIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
希望这对你有所帮助。
要将警报对话框的布局方向设置为RTL,可以使用OnShowListener方法。设置标题,消息后,....使用此方法。
dialog = alertdialogbuilder.create();
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dlg) {
dialog.getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL); // set title and message direction to RTL
}
});
dialog.show();