Android 仅显示操作栏的下半部分(位于状态栏后面)
由于某些原因,仅显示Android 仅显示操作栏的下半部分(位于状态栏后面),android,android-actionbar,Android,Android Actionbar,由于某些原因,仅显示操作栏的下半部分,而显示的下半部分位于状态栏后面。为什么会发生这种情况? 这只发生在抽屉中 这一定是安卓新版本的问题,因为我注意到安卓5.0.2和6.0中的漏洞。在Android 4.4.4中没有问题 我正在从android.support.v7.app.AppCompatActivity扩展我的活动,并在其中实现一些片段 这是我的应用程序配置: android { compileSdkVersion 22 buildToolsVersion "21.1.2"
操作栏的下半部分
,而显示的下半部分位于状态栏后面。为什么会发生这种情况?
这只发生在抽屉中
这一定是安卓新版本的问题,因为我注意到安卓5.0.2和6.0中的漏洞。在Android 4.4.4中没有问题
我正在从android.support.v7.app.AppCompatActivity
扩展我的活动
,并在其中实现一些片段
这是我的应用程序配置:
android {
compileSdkVersion 22
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.mypackage.myapp"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
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>
以下是一个屏幕截图,以便更好地理解:
谢谢大家! 在oncreate中添加此行
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
//then set status bar color or any thing else
}
请发布您的DrawerActivity
的布局。请同时发布styles.xml(特别是v21)以及活动的代码。到目前为止,我可以建议从“导航抽屉活动”模板创建一个应用程序,并将其与您的代码进行比较。到目前为止,它看起来还不错。您是否尝试过编译标准的“导航抽屉活动”应用程序?它是否按预期工作?(如果不是-我建议将buildToolsVersion更新到最新版本(23.1.2)。如果是-那么这是查找问题的快捷方式。感谢您的帮助,我将尝试并解决问题
@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();
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
//then set status bar color or any thing else
}