右对齐AlertDialog中的文本

时间:2011-05-29 14:29:27

标签: android alertdialog justify

我一直试图改变我的AlertDialog,以便它显示正确对齐的文本(希伯来文)。

在这里有inazaruk的帮助:Right justify text in AlertDialog 我设法让对话框显示,但它只能在模拟器(Eclipse)中正常工作。 当我将它移到我的设备上时(Xpersia X10a),屏幕顶部会出现警告框,背景会阻挡其背后的所有内容。

模拟器上的图像:

enter image description here

我的设备上的图片:

enter image description here

代码:

    public class test extends Activity {
    /** Called when the activity is first created. */

    public class RightJustifyAlertDialog extends AlertDialog {

        public RightJustifyAlertDialog(Context ctx) { 
              super(ctx, R.style.RightJustifyTheme); } }

   @Override
    public void onCreate(Bundle savedInstanceState) {
        final Context con = this;
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.main);

        Button button1 = (Button) findViewById(R.id.button1);
        button1.setOnClickListener(new View.OnClickListener(){

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                AlertDialog dialog = new RightJustifyAlertDialog(con);
                dialog.setButton("button", new OnClickListener(){           
                    public void onClick(DialogInterface arg0, int arg1)
                    {

                    }
                });

        dialog.setTitle("Some Title");
        dialog.setMessage("Some message");

        dialog.show();
            }

        });

    }
}

样式:

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

<style name="RightJustifyTextView" parent="@android:style/Widget.TextView">
    <item name="android:gravity">right|center_vertical</item>
    <item name="android:layout_centerVertical">true</item>
</style>

<style name="RightJustifyDialogWindowTitle" parent="@android:style/DialogWindowTitle" >
     <item name="android:gravity">right|center_vertical</item>
    <item name="android:layout_centerVertical">true</item>
</style>

<style name="RightJustifyTheme" parent="@android:style/Theme.Dialog.Alert">
    <item name="android:textViewStyle">@style/RightJustifyTextView</item>       
    <item name="android:windowTitleStyle">@style/RightJustifyDialogWindowTitle</item>       
</style>    

</resources>

我的设备正在使用Android 2.1-update1,模拟器设置为相同。

1 个答案:

答案 0 :(得分:0)

一个简单的事情要排除...检查设备的其他应用程序,看看是否所有应用程序都删除了其AlertDialog背景Alpha透明度。您可以尝试删除默认邮件应用程序中的某些内容,或者对项目进行长按删除的其他应用程序。我不认为有必要改变这种造型,但你永远不知道这些天Carriers会做什么。

相关问题