• 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);
        }
  • 相关阅读:
    修改 PHP 最大运行时间 max_execution_time
    去除桌面的不可清理的恶意图标
    SQL 性能调优 set statistics io
    SQL Server 2008 Failover Cluster
    [转]SQLSERVER数据存储内幕
    博客开通
    Entity FrameWork 4.3 实体属性为decimal时默认只保存2位小数
    FreeBSD常用命令及配置
    动态加载JS或CSS
    JS获取传入该页面的参数
  • 原文地址:https://www.cnblogs.com/xiaoQLu/p/2757100.html
Copyright © 2020-2023  润新知