2012-07-03 41 views
1

我想要書名的標題對話框。問題是與長標題,似乎默認標題對話框試圖微調,以適應該對話框寬度如何爲對話框對話框片段設置一個長標題?

enter image description here

超長文本於是我想出了通過刪除默認標題的解決方案此代碼

setStyle(STYLE_NO_TITLE, 0); 

將默認值替換爲文本視圖窗口小部件。這是我的自定義對話框XML

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <TextView 
     android:id="@+id/dialog_title" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" /> 

    <ListView 
     android:id="@+id/list" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" /> 

</LinearLayout> 

但是它只是混亂的對話框佈局

enter image description here

所以任何人都可以我一個更好的方式來處理呢?由於

+0

認爲您需要創建自己的自定義對話框。看看主題/樣式。 – Warpzit

+0

你能給我更多關於這方面的信息嗎?謝謝 – Huppo

+0

搜索開發者網站關於如何創建自定義對話框的對話框 – tyczj

回答

1

您可以使用google自定義視圖設置對話框

,但不要忘了dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); :)

1

因此,在您DialogFragments的onCreate您的setStyle:

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setStyle(DialogFragment.STYLE_NO_TITLE, R.style.Theme_Dialog); 
} 

然後你使用自己非常自定義的xml佈局在oncreateview()中創建對話框。

相關問題