Android工具栏,而不是操作栏

Mageno

我正在尝试使用工具栏而不是ActionBar。在Android 5.0。+中可以使用,但在4.4中,状态栏位于工具栏的顶部。

截屏:

截屏

布局:

<android.support.v7.widget.Toolbar
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="?attr/actionBarSize"   
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"     
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    android:background="@color/actionbar_color"/>

在OnCreate()中添加工具栏:

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

完整版式:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:fitsSystemWindows="true"
    android:layout_height="match_parent" >

    <LinearLayout
        android:id="@+id/drawer_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:minHeight="?attr/actionBarSize"   
            app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"     
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            android:background="@color/actionbar_color"/>

        <com.astuetz.PagerSlidingTabStrip
            android:id="@+id/tabs"
            android:textColor="@android:color/white"
            android:layout_width="match_parent"
            android:layout_height="48dip"
            android:background="@color/actionbar_color" />

        <android.support.v4.view.ViewPager
            android:id="@+id/pager"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_above="@+id/colors"
            android:layout_below="@+id/tabs"/>

    </LinearLayout>

    <LinearLayout
        android:id="@+id/left_drawer"
        style="@style/drawer_list"
        android:fitsSystemWindows="true"
        android:orientation="vertical">

         <ListView 
             android:id="@+id/mainMenu"
             android:layout_marginTop="10dp"
             android:layout_marginBottom="10dp"
             android:layout_width="match_parent"
             android:divider="@android:color/transparent"
             android:layout_height="wrap_content" />

    </LinearLayout>
</android.support.v4.widget.DrawerLayout>
哈维尔·塞哥维亚·科尔多瓦

添加一个frameLayout并在其高度中使用@dimen/statusBarHeight然后,您可以为每个版本(普通版,v19和v21)创建一个attrs.xml文件。在每个attrs.xml中,将<dimen name="statusBarHeight">25dp</dimen>25dp正常更改为0,在v19中更改为25,在v21中更改为0。您也可以为横向模式(values-land,values-land-v19等)创建attrs.xml。

<FrameLayout
        android:id="@+id/statusBar"
        android:layout_width="match_parent"
        android:layout_height="@dimen/statusBarHeight"
        android:background="?colorPrimaryDark"
        android:translationZ="4dp" />

    <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:elevation="4dp"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

看一下这个链接:Github

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Android工具栏,而不是操作栏

来自分类Dev

在工具栏/操作栏中更改文本颜色,Android?

来自分类Dev

Android隐藏操作栏和工具栏

来自分类Dev

在工具栏或操作栏的中心设置ActionBarDrawerToggle,Android吗?

来自分类Dev

Android Studio工具栏为操作栏错误

来自分类Dev

用工具栏替换操作栏

来自分类Dev

Android底栏重叠工具栏

来自分类Dev

Android工具栏+动作栏

来自分类Dev

Android ActionBar或工具栏

来自分类Dev

Android工具栏样式

来自分类Dev

Android工具栏更改

来自分类Dev

Android查找工具栏

来自分类Dev

Android:折叠线性布局而不是折叠工具栏

来自分类Dev

如何从片段Android断开工具栏操作

来自分类Dev

Android工具栏操作图标不起作用

来自分类Dev

如何从片段Android断开工具栏操作

来自分类常见问题

如何在Android Lollipop上声明扩展高度的工具栏/操作栏?

来自分类Dev

为什么不能在Android中使用工具栏覆盖操作栏?

来自分类Dev

Android的新工具栏和上下文操作栏如何协同工作?

来自分类Dev

如何在Android工具栏操作栏中为微调框设置正确的文本大小

来自分类Dev

工具栏未固定在顶部,并且小于android中的操作栏大小

来自分类Dev

找不到符号类操作栏和工具栏 [Android]

来自分类Dev

PopupWindow的变暗背景不包括工具栏/操作栏

来自分类Dev

工具栏和操作栏未显示在活动中

来自分类Dev

隐藏操作栏/工具栏时使内容动画化

来自分类Dev

将工具栏设置为片段中的操作栏

来自分类Dev

用工具栏替换操作栏后出现NullPointerException

来自分类Dev

操作栏中的工具栏选项?(扑)

来自分类Dev

在操作栏/工具栏上展开导航抽屉

Related 相关文章

热门标签

归档