2011-05-29 88 views
1

我一直在試圖改變我的AlertDialog,以便它顯示文本右對齊(希伯來語)。在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並且模擬器設置爲相同。

回答

0

排除一件簡單的事情...檢查您設備上的其他應用程序,看看是否所有應用程序都刪除了AlertDialog背景Alpha透明膠片。您可以嘗試刪除默認郵件應用程序中的某些內容或其他也有長按刪除項目的應用程序。我不認爲需要改變這種風格,但你永遠不知道運營商這幾天會做什麼。

+0

對話框可以在其他地方正常工作。此外,只有我更改的那個不起作用。如果我使用標準AlertDialog,那麼一切正常。 – theblitz 2011-05-29 15:13:03

+0

我忘記了包含代碼。現在修復了。 – theblitz 2011-05-29 17:33:29