【问题标题】:android Toolbar appbarlayoutandroid 工具栏 appbarlayout
【发布时间】:2016-11-18 10:33:59
【问题描述】:
 <?xml version="1.0" encoding="utf-8"?>
 <android.support.design.widget.CoordinatorLayout    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:layout_width="match_parent"
  android:layout_height="match_parent"
  tools:context=".Activity_Compose">

 <android.support.design.widget.AppBarLayout
     android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay"
    app:elevation="0dp">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:layout_gravity="right"
        android:background="?attr/colorPrimary"
        android:elevation="2dp"
        android:gravity="right"
        tools:targetApi="lollipop">

        <ImageView
            android:id="@+id/imgComposeCancel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="@dimen/min_padding"
            android:contentDescription="@string/image"
            app:srcCompat="@drawable/exit" />

        <com.example.CustomTextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Compose"
            android:textColor="@color/white"
            android:textSize="@dimen/min_textsize"
            app:font="@string/montserrat_regular" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center|right">

            <ImageView
                android:id="@+id/imgComposeAttach"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="@dimen/min_padding"
                android:contentDescription="@string/image"
                app:srcCompat="@drawable/mail_attach" />

            <ImageView
                android:id="@+id/imgComposeSend"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="@dimen/min_padding"
                android:contentDescription="@string/image"
                app:srcCompat="@drawable/mail_send" />

        </LinearLayout>

        </android.support.v7.widget.Toolbar>

   </android.support.design.widget.AppBarLayout>

      <include
         android:id="@+id/layout_dash_child"
         layout="@layout/act_compose_view" />


   </android.support.design.widget.CoordinatorLayout>

包含的布局在这里

  <?xml version="1.0" encoding="utf-8"?>
   <LinearLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:showIn="@layout/activity_compose">




     <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center|start"
        android:orientation="horizontal"
        android:padding="@dimen/most_min_padding"

        android:weightSum="2">


        <com.example.CustomTextView
            android:id="@+id/txtComposeTo"
            style="@style/label_text_secondary_compose_mail"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0.85"
            android:gravity="start"
            android:text="@string/to"
            app:font="@string/montserrat_light" />

        <com.doodle.android.chips.ChipsView
            android:id="@+id/chipsView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0.25"
            android:nextFocusDown="@+id/cstmBtnAddStaff"
            app:cv_max_height="130dp"
            app:cv_vertical_spacing="2dp" />

        <com.example.CustomButton
            android:id="@+id/cstmBtnAddStaff"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0.9"
            android:background="@color/blue"
            android:nextFocusDown="@+id/cstmBtnAddStaff"
            android:text="+"
            android:textColor="@android:color/white"
            android:textSize="20sp"
            app:font="@string/montserrat_regular" />


    </LinearLayout>

    <View
        android:layout_width="match_parent"
        android:layout_height="0.1dp"
        android:background="@color/not_black" />


    <com.example.CustomEditText
        android:id="@+id/txtComposeSubjectContent"
        style="@style/label_text_secondary_compose_mail"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/white"
        android:hint="Subject"
        android:maxLines="1"
        android:nextFocusDown="@+id/editor"
        android:padding="@dimen/most_min_padding"

        android:singleLine="true"
        android:textCursorDrawable="@drawable/cursor_color"
        app:font="@string/montserrat_light"
        app:met_hideUnderline="true" />

 </LinearLayout>

我的工具栏转到了状态栏的后面。我需要摆脱这个问题。帮助将被投票。我添加了学生,然后单击 txtComposeSubjectContent 编辑文本,包括工具栏在内的所有布局都已转到状态栏下方。这里发生了什么。我没有在这里添加任何样式。

【问题讨论】:

  • 你为什么要在工具栏中应用类似工具的标签:targetApi="lollipop"
  • 对于海拔="2dp"
  • 尝试删除该标签
  • 已删除。不工作
  • 在 CoordinatorLayout 中添加 android:fitsSystemWindows="true"

标签: android toolbar statusbar android-appbarlayout


【解决方案1】:

我认为您的问题取决于为 AppBarLayout 和 Toolbar 提供的高度,它从样式中选择高度,如果您不介意非常大的工具栏,请尝试使用 wrap_content。

其他方法可能是覆盖 AppBarLayout 和/或 Toolbar 的样式并使用标准填充/边距。

例如:

<style name="MyCustomTabLayout" parent="Widget.Design.TabLayout">
    <item name="tabTextAppearance">@style/MyCustomTextAppearance</item>
    <item name="padding">8dp</item>
</style>

<style name="MyCustomTextAppearance" parent="TextAppearance.Design.Tab">
    <item name="textAllCaps">false</item>
    <item name="android:textSize">@dimen/tab_text_size</item>
    <item name="android:textColor">@color/red</item>
</style>

正如您在此处看到的,我更改了 AppBar 布局的标准填充,并为我在 AppBar 中获得的一些选项卡的文本提供了自定义大小和颜色。

如果这些都不起作用,请让代码与您最初获得的代码一样,然后在不同的设备上尝试,如果您的问题仍然存在,因为您在工具栏中使用自定义视图,并且 onDraw() 方法可能由于不正确而发生冲突onMeasure() 方法,如果你真的想坚持这种方法,你会遇到很多麻烦。我认为您这样做是因为您想要 coordinatorLayout 行为,如果您不介意解释您想要实现的目标,我们可以提供不同的方法。

【讨论】:

  • 我认为这不是高度问题,它就像滚动问题。布局落后于状态栏。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-12
  • 1970-01-01
  • 2017-02-27
  • 1970-01-01
相关资源
最近更新 更多