动态的修改自定义custom title
16lz
2021-01-26
在android中 getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.text_title); 使用上面的话时 他所产生的并不是把以前的用现在的替换只是用 R.layout.text_title放在了默认样式的上面,如果你想通过一个按钮修改标题
以及view上的消息有两种方法:
private void setCustomTitleFeatureInt(int value) {
try { // retrieve value for com.android.internal.R.id.title_container(=0x1020149)
int titleContainerId = (Integer) Class.forName(
"com.android.internal.R$id").getField("title_container").get(null);
// remove all views from titleContainer
((ViewGroup) getWindow().findViewById(titleContainerId)).removeAllViews();
// add new custom title view
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, value);
} catch(Exception ex) {
// whatever you want to do here.. }
}
这种方法是取消以前的 不过这种方法可靠性不好
2.你可以用隐藏的方式:
findViewById(R.id.custom_title_1).setVisibility(View.GONE);getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title_2);
以及view上的消息有两种方法:
private void setCustomTitleFeatureInt(int value) {
try { // retrieve value for com.android.internal.R.id.title_container(=0x1020149)
int titleContainerId = (Integer) Class.forName(
"com.android.internal.R$id").getField("title_container").get(null);
// remove all views from titleContainer
((ViewGroup) getWindow().findViewById(titleContainerId)).removeAllViews();
// add new custom title view
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, value);
} catch(Exception ex) {
// whatever you want to do here.. }
}
这种方法是取消以前的 不过这种方法可靠性不好
2.你可以用隐藏的方式:
findViewById(R.id.custom_title_1).setVisibility(View.GONE);getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title_2);
更多相关文章
- Android(安卓)spinner 样式及其使用详解
- TextInputEditText样式设置
- 定义seekbar样式
- Android中使用NavigationView实现抽屉侧滑效果中Menu菜单栏设置
- Android判断Activity是否全屏的方式!!!(最全)
- 定制个性化屏保
- [置顶] Android中遇到的需求与解决方案一
- android 底部tab
- 自定义Toast