zoukankan      html  css  js  c++  java
  • android ListActivity自定义标题栏

    android 自定义标题栏的步骤是

    protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
            // 这里要主要requestWindowFeature和setContentView先后顺序哦
            setContentView(R.layout.main);
            getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title_1);
        }

    但是这个在ListActivity中好像无效,因为ListActivity没有调用setContentView方法,网上的一些解决方法都是在onCreate中调用setContentView,也就是自己实现layout,

    有没有更简单的方法呢,使用上面的那样,

    其实是有的,在ListActivity中有一个方法很容易被忽略,ensureList(),这是唯一一个设置了layout的地方,但是不是在oncreate中设置的,listActivity没有实现onCreate方法,

    继续找,发现在onRestoreInstanceState(), setListAdapter()和getListView()中调用了,也就是说在这3个方法中都有可能会执行setContentView方法,

    知道这个就好办了,

    解决方法一:在oncreate方法中调用getListView()代替掉上面的setContentView(R.layout.main)

    protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
            //代替掉setContentView
            getListView();
            getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title_1);
        }

    解决方法二:找到你的activity调用setListAdapter的地方,在后面加上面最后一句

    protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
            /**
             * 你自己的代码
             */
            setListAdapter(adapter);
            getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title_1);
        }
  • 相关阅读:
    家庭作业 3.66
    存储器层次结构
    PHP empty()函数说明---用了N遍了就是记不住
    如何让mysql的自动递增的字段重新从1开始呢?(
    dirname(__FILE__) 的使用总结
    又回来了
    Ecshop 后台增加一个左侧列表菜单menu菜单的方法
    用PHP上传文件时$_FILES中error返回值详解
    ECSHOP站内页面跳转,避免死链
    比特币Bitcoin-qt客户端加密前后如何导入导出私钥?
  • 原文地址:https://www.cnblogs.com/xiaoQLu/p/2757100.html
Copyright © 2011-2022 走看看