2013-10-30 37 views
0

我希望有我的自定義標題爲我CustomAlert。 我爲Dialog的標題自定義佈局做了什麼?Editset自定義佈局標題我的對話框

EDIT2: 我加入我的代碼:

protected Dialog onCreateDialog(int id) 
     {   
      switch(id) 
      {   
      case Dialog_Reset :  
      Dialog dialog=new Dialog(this); 
      dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
      dialog.setContentView(R.layout.about); 
      dialog.setCanceledOnTouchOutside(true);   
      return dialog; 
      } 
      return super.onCreateDialog(id); 
     } 

和becuse我不喜歡在對話框中默認的頭,我現在將其刪除,而我學有我的自定義標題。

+0

http://stackoverflow.com/questions/2644134/android-how -to-create-a-dialog-without-a-title –

回答

1

,但我不明白什麼是 「titleId」。這是真的嗎?是我的 特別佈局設計,我想用於標題?

titleId:標題標識符換句話說字符串資源標識符,例如, R.string.app_name。您可以在res>values文件夾

Android開發文檔發現strings.xml添加這些:Dialog.setTitle (int titleId)

更多關於字符串資源here

+0

我想要我的自定義標題對話框 –

+0

是否有可能? –

0

您可以設置Alert Dialog使用public AlertDialog.Builder setCustomTitle (View customTitleView)方法CustomTitle

按照文檔

公共AlertDialog.Builder setCustomTitle(查看customTitleView)

設置使用自定義視圖customTitleView稱號。 setTitle(int)和setIcon(int)方法對於大多數標題應該足夠了,但如果標題需要更多定製,則會提供此方法。使用這將通過其他方法替換標題和圖標集。

參數 customTitleView自定義視圖爲標題中使用。 返回 該生成器對象,允許調用鏈接設置方法

例如

LayoutInflater inflater = (LayoutInflater)yourClass.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
View yourView= inflater.inflate(R.layout.custom_dialog, null); 

AlertDialog.Builder ab= new AlertDialog.Builder(this); 
ab.setCustomTitle(yourView); 
ab.setMessage(message); 
... 


ab.create(); 
ab.show(); 

詳細請見documentation

+0

但啥子是「你的觀點」 –

+0

@setareshojaei'yourView'是要在標題顯示自定義視圖。 –

+0

我想要一個標題與我的layout.is它我的XML視圖ID? –

相關問題