android.util.AndroidRuntimeException: You cannot combine custom titles with other title features

为了实现是定义title,我们会加上

requestWindowFeature(Window.FEATURE_CUSTOM_TITLE)和
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.title)这两句代码

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

           
        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        setContentView(R.layout.activity_order_scan);
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.title);

title.xml






    
    

如果出现如下异常:

android.util.AndroidRuntimeException: You cannot combine custom titles with other title features

 

解决方案:

 1、不能用默认主题,需要自定义

 

android.util.AndroidRuntimeException: You cannot combine custom titles with other title features_第1张图片

2、将默认的主题AppTheme改成自定义主题
注意:自定义主题parent必须"Theme.AppCompat"开头,否则仍然报上面的错。我这里选择"Theme.AppCompat.Light.NoActionBar",如果不带"NoActionBar"的主题自定义title和默认的title都会显示。所以要选一款带"NoActionBar"的主题

android.util.AndroidRuntimeException: You cannot combine custom titles with other title features_第2张图片
3、在主题中将   android:windowNoTitle、android:windowActionBar、android:windowActionBarOverlay这三项都设置false


 

你可能感兴趣的:(Android)