一、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();