setTitle到AppCompatDialog不起作用

Edd*_*his 4 android dialog android-appcompat

我正在尝试使用新AppCompat 22.1功能AppCompatDialog,但它显示我没有标题的对话框,但我正在使用方法setTitle.如果我改变了AppCompatDialogDialog一切工作正常.这是一个错误AppCompatDialog吗?

这是我的对话框代码:

final AppCompatDialog dialog = new AppCompatDialog(ctx);
dialog.setTitle(R.string.choose_mode);
dialog.setContentView(R.layout.dialog_with_list);

ListView listView = (ListView) dialog.findViewById(R.id.list_view);

List<ModeItemModel> modesList = new ArrayList<ModeItemModel>();
modesList.add(new ModeItemModel(GUI_MANUAL));
modesList.add(new ModeItemModel(GUI_GPS));
listView.setAdapter(new ModeItemsAdapter(ctx, R.layout.list_item_ico_with_text, modesList));
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
        //Do Action

        dialog.cancel();
    }
});
dialog.setCancelable(true);
dialog.show();
Run Code Online (Sandbox Code Playgroud)

Sve*_*ven 6

正如@Eddwhis在上面的评论中指出的<item name="windowNoTitle">true</item>那样,主题中也隐藏了对话框的标题.我通过添加自定义AppCompatDialgStyle来修复它,我在其中设置<item name="windowNoTitle">false</item>为false.

基本主题:

<style name="Theme.App.Base" parent="Theme.AppCompat.Light.DarkActionBar,">
   ...
   <item name="alertDialogTheme">@style/Theme.App.AppCompatDialogStyle</item>
   <item name="dialogTheme">@style/Theme.App.AppCompatDialogStyle</item>
</style>
Run Code Online (Sandbox Code Playgroud)

NoActionBar主题:

<style name="Theme.App.NoActionBar" parent="@style/Theme.App.Base">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>
Run Code Online (Sandbox Code Playgroud)

我的对话风格:

<style name="Theme.App.AppCompatDialogStyle" parent="Theme.AppCompat.Light.Dialog">
    <item name="colorAccent">#f00</item>
    <item name="android:textColorPrimary">@color/black</item>
    <item name="android:background">@color/red</item>
    <item name="windowNoTitle">false</item> <!-- that's the important bit -->
</style>
Run Code Online (Sandbox Code Playgroud)