开发者

Right justify text in AlertDialog

开发者 https://www.devze.com 2023-03-08 21:35 出处:网络
I have been trying to alter my AlertDialog so that it will show the text right justified (for Hebrew).

I have been trying to alter my AlertDialog so that it will show the text right justified (for Hebrew).

With inazaruk's help here: Right justify text in AlertDialog I managed to get the dialog showing but it only works correctly in the emulator (Eclipse). When I move it onto my device (Xpersia X10a) the alert box appears at the top of the screen with the background blocking out everything behind it.

The image on the emulator:

Right justify text in AlertDialog

The image on my device:

Right justify text in AlertDialog

Code:

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

        });

    }
}

Styles:

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

<style name="RightJustifyTextView" parent="@andro开发者_开发问答id: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>

My device is working with Android 2.1-update1 and the emulator is set to same.


One simple thing to rule out... Check you device's other apps to see if all of them have had their AlertDialog background alpha transparencies removed. You can try deleting something in the default mail application, or other applications that also have a long press delete for items. I wouldn't see the need to change this styling, but you never know what Carriers are going to do these days.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号