Android自定义工具栏重叠状态栏:如何解决它

Android自定义工具栏重叠状态栏:如何解决它,第1张

概述我正在使用 Android应用程序的项目. 我的代码如下: 我的activity_mainmenu.xml <?xml version="1.0" encoding="utf-8"?><android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 我正在使用 Android应用程序的项目.

我的代码如下:

我的activity_mainmenu.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"    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>

我的工具栏

<androID.support.v7.Widget.Toolbar    xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:layout_wIDth="match_parent"    androID:layout_height="?attr/actionbarSize"    androID:layout_alignParentleft="true"    androID:layout_alignParenttop="true"    androID:fitsSystemwindows="true"    androID:elevation="4dp"    androID:popuptheme="@style/themeOverlay.AppCompat.light"    androID:theme="@style/themeOverlay.AppCompat.Dark.Actionbar">    <FrameLayout        androID:layout_wIDth="match_parent"        androID:layout_height="match_parent">        <TextVIEw            androID:ID="@+ID/toolbar_Title"            androID:orIEntation="horizontal"            androID:layout_wIDth="wrap_content"            androID:layout_height="fill_parent"            androID:layout_gravity="left"            androID:gravity="center_vertical"            androID:text="@string/app_name"             />        <TextVIEw            androID:ID="@+ID/toolbar_audio"            androID:orIEntation="horizontal"            androID:layout_wIDth="wrap_content"            androID:layout_height="fill_parent"            androID:layout_gravity="right"            androID:layout_marginRight="80dp"            androID:gravity="center_vertical"            androID:textcolor="@color/background_gradIEnt_start"            androID:text="@string/audio"            androID:visibility="gone"/>        <TextVIEw            androID:ID="@+ID/toolbar_vIDeo"            androID:orIEntation="horizontal"            androID:layout_wIDth="wrap_content"            androID:layout_height="fill_parent"            androID:layout_gravity="right"            androID:layout_marginRight="10dp"            androID:gravity="center_vertical"            androID:textcolor="@color/background_gradIEnt_start"            androID:text="@string/vIDeo"            androID:visibility="gone"/>        <Radiobutton                androID:layout_wIDth="wrap_content"                androID:layout_height="fill_parent"                androID:text="Audio"                androID:layout_gravity="right"                androID:layout_marginRight="80dp"                androID:ID="@+ID/radiobuttonAudio"                androID:checked="true"                androID:buttonTint="@color/background_gradIEnt_start"/>        <Radiobutton                androID:layout_wIDth="wrap_content"                androID:layout_height="fill_parent"                androID:text="VIDeo"                androID:ID="@+ID/radiobuttonVIDeo"                androID:layout_gravity="right"                androID:layout_marginRight="10dp"                androID:gravity="center_vertical"                androID:checked="false"                androID:buttonTint="@color/background_gradIEnt_start"/>    </FrameLayout></androID.support.v7.Widget.Toolbar>

和AndroIDManifest.xml

<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>

用androID:theme =“@ style / UAmpApptheme”

<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>

而且:

@OverrIDepublic 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","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;    }

我的自定义 *** 作工具栏有问题:

>自定义工具栏重叠在状态栏下方

如何解决它.

见图:

发生此问题(Build.VERSION.SDK_INT< Build.VERSION_CODES.KITKAT_WATCH) (Build.VERSION.SDK_INT> = Build.VERSION_CODES.KITKAT_WATCH)不会发生此问题

见图像:

谢谢

解决方法 您是否尝试将app:layout_behavior =“@ string / appbar_scrolling_vIEw_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自定义工具栏重叠状态栏:如何解决它全部内容,希望文章能够帮你解决Android自定义工具栏重叠状态栏:如何解决它所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1123646.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存