For some reason only the lower half of the ActionBar
is being displayed, and the half that is showing is behind the status bar. Why could this happen? This happens only in the DrawerActivity
.
出于某种原因,仅显示ActionBar的下半部分,显示的一半在状态栏后面。为什么会这样?这只发生在DrawerActivity中。
It must be something with the newer versions of Android because I noticed the bug in Android 5.0.2 and 6.0. In Android 4.4.4 there is no issue.
它必须是新版Android的东西,因为我注意到了Android 5.0.2和6.0中的错误。在Android 4.4.4中没有问题。
I'm extendig my Activity
from the android.support.v7.app.AppCompatActivity
and implementing some fragments in it.
我从android.support.v7.app.AppCompatActivity扩展我的Activity并在其中实现一些片段。
This is my app configuration:
这是我的应用配置:
android {
compileSdkVersion 22
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.mypackage.myapp"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
The layout for the DrawerActivity
DrawerActivity的布局
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="false"
tools:openDrawer="start">
<include
layout="@layout/app_bar_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_drawer"
app:menu="@menu/activity_drawer_drawer" />
</android.support.v4.widget.DrawerLayout>
styles.xml :
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>
onCreate
method of DrawerActivity
:
onGreate DrawerActivity方法:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_drawer);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
//Setting floating button
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
//Setting up default fragment.
Fragment fragment = HomeFragment.newInstance(null, null);
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.mainFrame, fragment);
ft.commit();
}
Here's a screenshot for better understanding:
这是一个更好理解的截图:
Thank you!
1 个解决方案
#1
0
Add this line in your oncreate
在你的oncreate中添加这一行
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
//then set status bar color or any thing else
}
#1
0
Add this line in your oncreate
在你的oncreate中添加这一行
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
//then set status bar color or any thing else
}