PreferenceActivity里自定义标题栏(title bar)出错:requestFeature() must be called before ad
来源:互联网 发布:miss淘宝店外设店 编辑:程序博客网 时间:2024/06/04 23:18
一般activity里自定义标题栏时候,我们一般会遵循一个顺序:
final boolean isCustom = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);setContentView(R.layout.you_layout);if(isCustom){getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_tiltebar);
}复制代码就是说,界面的属性(这里指的是window的属性)一般要在展示界面内容(setContentView)之前确定,这个也符合逻辑。然后,今天在我使用preferenceActivity时候,出错了:requestFeature() must be called before adding content。相关代码如下:
super.onCreate(savedInstanceState);final boolean isCustom = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);addPreferencesFromResource(R.xml.preferences);if(isCustom){getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_tiltebar);}
复制代码网上查了下,没有结果,于是我觉得是不是super.onCreate(savedInstanceState)里面有文章,进入源码一看,果然:
@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(com.android.internal.R.layout.preference_list_content);mPreferenceManager = onCreatePreferenceManager();getListView().setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);}
复制代码可以看出,在super.onCreate(savedInstanceState) 里面就出现了活动界面内容的展示,即调用setcontentview方法。于是把requestFeature()方法放在super.onCreate(savedInstanceState)前面,就ok了
0 0
- PreferenceActivity里自定义标题栏(title bar)出错:requestFeature() must be called before ad
- PreferenceActivity里自定义标题栏(title bar)出错:requestFeature() must be called before adding content
- requestFeature() must be called before adding content
- requestFeature() must be called before adding content
- requestFeature() must be called before adding content
- requestFeature() must be called before adding content
- requestFeature() must be called before adding content
- requestFeature() must be called before adding content
- requestFeature() must be called before adding content
- requestFeature() must be called before adding content
- android异常信息:requestFeature() must be called before adding content
- 解决requestFeature() must be called before adding content错误
- 解决requestFeature() must be called before adding content错误
- 解决requestFeature() must be called before adding content错误
- 解决requestFeature() must be called before adding content错误
- 解决requestFeature() must be called before adding content错误
- 解决requestFeature() must be called before adding content错误
- 【遇见Android bug】requestFeature() must be called before adding content
- LINUX修改IP地址
- XML的简单读取与写入
- php xhprof 扩展的使用
- linux中pip安装步骤与使用详解
- java.net.MalformedURLException: Local host name unknown: java.net.UnknownHostExce
- PreferenceActivity里自定义标题栏(title bar)出错:requestFeature() must be called before ad
- VB批处理后重定向输出
- oracle无法删除当前已连接的用户
- c++ windows下的简单的日志输出DebugPrintf
- mongodb 命令
- OC之Protocol(协议)
- 反射
- mac下安装php-redis扩展
- hdu4352(数位dp+状态压缩)