Android自定义工具栏重叠状态栏:如何解决
我正在为android应用程序项目工作 我的代码如下: 我的活动\u main menu.xmlAndroid自定义工具栏重叠状态栏:如何解决,android,android-layout,Android,Android Layout,我正在为android应用程序项目工作 我的代码如下: 我的活动\u main menu.xml <?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<RelativeLayout xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#ff8400">
<ListView
android:id="@+id/list_view_push"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<include android:id="@+id/toolbar" layout="@layout/include_toolbar"/>
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/toolbar">
</android.support.v4.view.ViewPager>
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
<application
android:name="............AppController"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/UAmpAppTheme" >
<!--This meta-data tag is required to use Google Play Services.-->
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/>
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:screenOrientation ="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
....................
自定义操作工具栏有问题:
- 状态栏下方的自定义工具栏重叠
谢谢您是否尝试将
app:layou behavior=“@string/appbar\u scrolling\u view\u behavior”
添加到您的相对布局中?像这样
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<RelativeLayout xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#ff8400"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<ListView
android:id="@+id/list_view_push"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<include android:id="@+id/toolbar" layout="@layout/include_toolbar"/>
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/toolbar">
</android.support.v4.view.ViewPager>
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
我刚刚找到了解决问题的方法 现在,我将分享给大家 如标题所示:Android自定义工具栏重叠状态栏:如何解决它 这个问题发生在 (Build.VERSION.SDK\u INT
android:background=“#ff8400”>
希望能帮助大家
感谢阅读请尝试从activity_main menu.xml中删除android:fitsystemwindows=“true”发布您想要的屏幕?你想喜欢“闲逛”的布局吗?Hi Shishram,我想在这个应用程序中使用它。Hi TdSoft我只是尝试添加。。。但还是会发生。
<style name="UAmpAppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowContentTransitions">true</item>
<item name="colorPrimary">#ffff5722</item>
<item name="colorPrimaryDark">#ffbf360c</item>
<item name="colorAccent">#ffff5722</item>
</style>
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mainmenu);
initializeToolbar();
protected void initializeToolbar() {
mToolbar = (Toolbar) findViewById(R.id.toolbar);
if (mToolbar == null) {
throw new IllegalStateException("Layout is required to include a Toolbar with id " +
"'toolbar'");
}
mToolbar.inflateMenu(R.menu.main);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolbar, R.string.open_content_drawer, R.string.close_content_drawer);
mDrawerLayout.setDrawerListener(mDrawerListener);
mDrawerLayout.setStatusBarBackgroundColor(ResourceHelper.getThemeColor(this, R.attr.colorPrimary, android.R.color.black));
populateDrawerItems();
setSupportActionBar(mToolbar);
updateDrawerToggle();
} else {
setSupportActionBar(mToolbar);
}
//int resourceIdnavigation_bar_height = getResources().getIdentifier("navigation_bar_height", "dimen", "android");
//if (resourceIdnavigation_bar_height > 0) {
//LogHelper.d("MainMenu", " Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH 1 " + getResources().getDimensionPixelSize(resourceIdnavigation_bar_height));
//};
//int resourceIdstatus_bar_height = getResources().getIdentifier("status_bar_height", "dimen", "android");
// if (resourceIdstatus_bar_height > 0) {
//LogHelper.d("MainMenu", " Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH 2 " + getResources().getDimensionPixelSize(resourceIdstatus_bar_height));
// }
mToolbarInitialized = true;
}
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<RelativeLayout xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#ff8400"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<ListView
android:id="@+id/list_view_push"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<include android:id="@+id/toolbar" layout="@layout/include_toolbar"/>
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/toolbar">
</android.support.v4.view.ViewPager>
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true" <!-- remove this line -->
tools:context=".MainActivity">
<RelativeLayout xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:fitsSystemWindows="true" <!-- add here -->
android:background="#ff8400">
<ListView
android:id="@+id/list_view_push"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<include android:id="@+id/toolbar" layout="@layout/include_toolbar"/>
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/toolbar">
</android.support.v4.view.ViewPager>
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>