簡體   English   中英

Android:更改警報對話框圖標的位置

[英]Android : change the position of alert dialog icon

我在 android xml 文件中有一個警報對話框。我的警報對話框的左側有一個圖標。我想將圖標的位置更改到右側。 我也不想<\/strong>使用自定義對話框<\/strong>

像這樣 :

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();

您只需要在 res/values/styles 中創建一個樣式標簽並編寫:

<style name="alertDialog LayoutDirection">
    <item name="android:layoutDirection">rtl</item>
</style>

然后在您的活動中初始化警報對話框后添加它:

alertDialog.setView(R.style.alertDialog);

例如 :

AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this);
            alertDialog.setMessage("حذف بشه؟")
                    .setCancelable(true);
            alertDialog.setPositiveButton("آره", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    Toast.makeText(MainActivity.this, "yes", Toast.LENGTH_SHORT).show();
                }
            });
            alertDialog.setNegativeButton("نه", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    Toast.makeText(MainActivity.this, "nooo", Toast.LENGTH_SHORT).show();
                }
            });

            alertDialog.show();
            alertDialog.setView(R.style.alertDialog);
            

恐怕你除了定制別無選擇。 常見的對話框在 UI 更改中是相當靜態的。 您可以設置另一個標題、按鈕或更改圖像,但不能重新定位它們。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM