随笔2

一、fitsSystemWindows:

1、作用:android:fitsSystemWindows=”true” 这个属性的作用就是通过设置View的padding,使得应用的content部分——Activity中setContentView()中传入的就是content——不会与system window重叠。

2、注意:需要被设置给根View——这个属性可以被设置给任意View,但是只有根View(content部分的根)外面才是SystemWindow,所以只有设置给根View才有用。

3、无论在什么平台上,fitsSystemWindows都会影响Insets,使你的content和system ui不会重叠——除非你自定义这一行为。

二、AppBarLayout与Recyclerview重叠

这里写图片描述
解决方法:在recycelrview中添加;
注意:这个属性跟滑动导致appbarlayout划出没关系

app:layout_behavior="@string/appbar_scrolling_view_behavior"

注意:控制AppBarLayout中哪个会滑出屏幕,哪个停在屏幕顶部的属性是:

app:layout_scrollFlags="scroll|enterAlways"
此属性不属于CollapsingToolbarLayout

3、修改toolbar的整体颜色
这里写图片描述
toolbar的字体颜色本身有属性可以改,但是旁边的actionBarDrawerToggle颜色只有通过style
1、如果想字体和actionBarDrawerToggle都改成白色,可以使用下面方法

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"/>

<android.support.v7.widget.Toolbar
            android:id="@+id/home_toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_scrollFlags="scroll|enterAlways"
            android:theme="@style/AppTheme.AppBarOverlay"
            app:title="新闻资讯" />

2、单独修改actionBarDrawerToggle颜色
这里写图片描述

    <style name="DrawerArrowStyle" parent="@style/Widget.AppCompat.DrawerArrowToggle">
        <item name="spinBars">true</item>
        <item name="color">@android:color/holo_red_dark</item>
    </style>

    <style name="BaseAppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:screenOrientation">portrait</item>
        <item name="android:windowTranslucentStatus" tools:targetApi="kitkat">true</item>
        <item name="android:windowTranslucentNavigation" tools:targetApi="kitkat">true</item>
        <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
    </style>

Options menu切换问题

这里写图片描述

    //最基本的创建Options menu
@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.about_news_menu, menu);
        return true;
    }

    //部分手机可以在showAsAction为ifroom的时候,无法出现overflower按钮,该方法解决这个问题
    @Override
    public boolean onMenuOpened(int featureId, Menu menu) {
        if (featureId == Window.FEATURE_ACTION_BAR && menu != null) {
            if (menu.getClass().getSimpleName().equals("MenuBuilder")) {
                try {
                    Method method = menu.getClass().getDeclaredMethod("setOptionalIconsVisible", Boolean.TYPE);
                    method.setAccessible(true);
                    method.invoke(menu, true);
                } catch (NoSuchMethodException e) {
                    e.printStackTrace();
                } catch (InvocationTargetException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
            }
        }
        return super.onMenuOpened(featureId, menu);
    }

    //这是真正进行切换Options menu的方法
    @Override
    public boolean onPrepareOptionsMenu(Menu menu) {
        //每次需要先把之前的menu清空
        menu.clear();
        MenuInflater menuInflater = getMenuInflater();
        //currentMenuPosition自己定义的成员变量,自己在相应的点击事件处进行赋值
        switch (currentMenuPosition){
            case 0:
                menuInflater.inflate(R.menu.about_news_menu, menu);
                break;
            case 1:
                menuInflater.inflate(R.menu.about_photo_menu, menu);
                break;
            default:
                menuInflater.inflate(R.menu.about_setting_menu, menu);
                break;
        }
        return super.onPrepareOptionsMenu(menu);
    }

现在还有一个问题,什么时候系统会调用onPrepareOptionsMenu?

有个方法可以对menu进行刷新,然后会调用onPrepareOptionsMenu方法

    //什么时候进行刷新,直接调用该语句
      invalidateOptionsMenu();
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值