带有AppCompat主题的Android DialogFragment [英] Android DialogFragment with AppCompat theme issue
本文介绍了带有AppCompat主题的Android DialogFragment的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图用AppCompat主题创建DialoFragment,但是当我使用AppCompat主题时,对话框标题未显示.
I've trying to create DialoFragment with AppCompat theme, but when i use AppCompat theme, dialog title is not shown.
我正在使用定义的样式:
I'am using defined style:
<style name="DialogFragment" parent="Theme.AppCompat.Light.Dialog"/>
将父主题更改为:
<style name="DialogFragment" parent="android:Theme.Material.Light.Dialog"/>
或
<style name="DialogFragment" parent="android:Theme.Holo.Light.Dialog"/>
标题显示正确.
我的对话框代码:
public class InfoDialog extends DialogFragment {
public static final String TAG = InfoDialog.class.getName();
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Dialog dialog = super.onCreateDialog(savedInstanceState);
dialog.getWindow().setTitle(getString(R.string.dialog_title));
return dialog;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NORMAL, R.style.DialogFragment);
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.info_dialog, container, false);
}
}
任何想法是导致问题的原因吗?
应用程序使用com.android.support:appcompat-v7:22.2.0
,也许这是平台错误?
Any ideas what is causing the issue?
Application use com.android.support:appcompat-v7:22.2.0
, maybe this is platform bug?
推荐答案
尝试扩展 AppCompatDialogFragment 而不是DialogFragment.那应该可以解决问题.
Try extending AppCompatDialogFragment instead of DialogFragment. That should do the trick.
这篇关于带有AppCompat主题的Android DialogFragment的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文