2012-05-06 44 views
8

我正在用希伯來語(這是rtl)編寫一個應用程序。 當我設置我的標題爲它出現在左邊的對話框片段。 我試圖使它顯示在右側做:設置對話框片段標題從右邊顯示

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
     Bundle savedInstanceState) 
{ 
    //set's up the title for this dialog fragment 
    getDialog().getWindow().setGravity(Gravity.RIGHT); 
    getDialog().setTitle(R.string.find_Address_text); 

但它不會影響冠軍的位置。 我怎麼能做到這一點? TNX

+0

我用這個方法:http://stackoverflow.com/questions/14439538/how-can-i-change-the-color-of-alertdialog-title-and-the-color-of-the-line-/23278774#23278774 –

回答

18

隱藏默認標題並在佈局中製作一個自定義標題。

要隱藏默認標題:

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setStyle(STYLE_NO_TITLE, 0); // remove title from dialogfragment 
} 

然後一個TextView與您的首選樣式添加到佈局的頂部:

<TextView 
android:id="@+id/dialog_title" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:gravity="right|center" 
android:text="@string/dialog_title" /> 
+3

+1 for setStyle(STYLE_NO_TITLE) –

+0

2美分的問題是:如何將主題視爲實際對話標題?並使用手機主題? –

+0

@Waza_Be個人而言,我現在使用HoloEverywhere作爲我的應用程序,這樣整個主題在各種API中都是相同的。除此之外,我能想到的唯一的事情是,如果可以從API中找到它(android.R.something),然後設置重力,也許可以製作標題視圖的副本。但我不確定這是可能的。 – Samutz

6

我知道這是一個古老的線程有一個答案。但對於其他人可能有相同的問題:

@Override 
public Dialog onCreateDialog(Bundle savedInstanceState) { 
    Dialog dlg = super.onCreateDialog(savedInstanceState); 

    dlg.setTitle("Title"); 
    TextView titleTextView = (TextView) dlg.findViewById(android.R.id.title); 
    titleTextView.setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL); 

    return dlg; 
} 

這樣我們有標題欄,我們不需要做一個自定義的。