2015-11-03 36 views
8

上顯示除法我有這個類:打開AlertDialog不清單

public class PageDetailInfoView extends FrameLayout { 

//few constructors and methods 

//method to show an AlertDialog with a list 
private void openDialog(){ 

    List<String> mTags = new ArrayList<String>(); 
    mTags.add("Item1"); 
    mTags.add("Item2"); 
    mTags.add("Item3"); 
    mTags.add("Item4"); 
    mTags.add("Item5"); 
    mTags.add("Item6"); 

    final CharSequence[] tags = mTags.toArray(new String[mTags.size()]); 
    AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); 
    builder.setTitle("Title"); 
    builder.setItems(tags, new DialogInterface.OnClickListener() { 
     public void onClick(DialogInterface dialog, int item) { 
     //do something 
     } 
    }); 

    Dialog alertDialogObject = builder.create(); 
    alertDialogObject.show(); 


} 

警告對話框後調用openDialog(),但事情是,它並沒有表現出項目之間的分隔。 我希望得到這樣的:
http://2.bp.blogspot.com/-i00d8VG6WsQ/UrGIeyb-8II/AAAAAAAAHwA/8MPWP5qrQ78/s500/alertdialog-with-simple-listview.png

,事實上,我得到它,但沒有灰色分隔。
有關爲什麼的任何想法?

enter image description here

回答

26

變化AlertDialog列表項分隔顏色:

AlertDialog alertDialogObject = dialogBuilder.create(); 
ListView listView=alertDialogObject.getListView(); 
listView.setDivider(new ColorDrawable(Color.BLUE)); // set color 
listView.setDividerHeight(2); // set height 
alertDialogObject.show(); 
+0

謝謝,但我不能訪問.getListView() – JoCuTo

+2

這個工程!但你必須改變'對話alertDialogObject = dialogBu​​ilder.create();'AlertDialog alertDialogObject = dialogBu​​ilder.create(); ' –

+0

是的作品!非常感謝 – JoCuTo

0

這可能是因爲你正在運行您的Android應用5.0+具有材質設計。

爲了讓「老」的樣子,只是構築你的對話與霍洛風格:

ContextThemeWrapper themedContext = new ContextThemeWrapper(getContext(), android.R.style.Theme_Holo_Light_Dialog_NoActionBar); 
AlertDialog.Builder builder = new AlertDialog.Builder(themedContext); 
// ... then create your dialog 

雖然這看起來怪異對於一些用戶(特別是棒棒糖和棉花糖,所以我建議考慮使用自定義你的對話框的視圖

+0

謝謝丹尼爾,好點但不起作用,仍然沒有分隔線:( – JoCuTo

+0

你可能會添加一個關於你當前進度的截圖嗎? –

+0

關於添加的截圖 – JoCuTo