【问题标题】:Removing Shadow From Toolbar Buttons去除工具栏按钮的阴影
【发布时间】:2017-10-04 23:44:44
【问题描述】:

我想从工具栏中的这些图像按钮中删除阴影,但我似乎无法做到。我试过设置高程、无边框样式,并将 stateListAnimator 设置为 null。 (这些是对其他帖子的建议。)

编辑:在下面找到更新的 XML。为了消除阴影,我尝试了每一个建议。 (甚至几乎将它们全部组合起来)但我仍然无法摆脱它们。

主布局

<?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">
    <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        tools:context="com.tqamobile.partyme.MainActivity">
        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/AppTheme.AppBarOverlay">
            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                app:popupTheme="@style/AppTheme.PopupOverlay">
                <LinearLayout
                    android:layout_width="wrap_content"
                    android:background="#00aaaaaa"
                    android:layout_gravity="right"
                    android:layout_height="match_parent">
                    <ImageButton
                        android:id="@+id/notification_button"
                        android:layout_height="match_parent"
                        android:layout_width="wrap_content"
                        android:elevation="0dp"
                        android:background="@android:color/transparent"
                        android:stateListAnimator="@null"
                        android:theme="@style/AppTheme.ToolbarButton"
                        android:src="@drawable/ic_no_notifications_action" />
                </LinearLayout>
            </android.support.v7.widget.Toolbar>
        </android.support.design.widget.AppBarLayout>
        <include
            layout="@layout/content_main" />
    </android.support.design.widget.CoordinatorLayout>
    <android.support.design.widget.NavigationView
        android:id="@+id/navigation_view"
        android:layout_height="match_parent"
        android:layout_width="wrap_content"
        android:layout_gravity="start"
        app:itemTextColor="@color/colorAccent"
        app:headerLayout="@layout/nav_header"
        app:menu="@menu/menu_navigation" />
</android.support.v4.widget.DrawerLayout>

样式

<style name="AppTheme.ToolbarButton" parent="@style/Widget.AppCompat.Button.Borderless"/>

【问题讨论】:

    标签: android android-layout


    【解决方案1】:

    将按钮的背景从您当前的属性更改为@null,如下所示:

    android:background="@null"
    

    【讨论】:

      【解决方案2】:

      您应该将按钮添加为菜单项。

      完整指南:https://stackoverflow.com/a/31477092/4974603

          <?xml version="1.0" encoding="utf-8"?>
         <menu
              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"
              tools:context=".MainActivity">
              <item
                  android:id="@+id/action_settings"
                  android:orderInCategory="100"
                  android:title="@string/action_settings"
                  app:showAsAction="never" />
              <item
                  android:id="@+id/action_search"
                  android:orderInCategory="200"
                  android:title="Search"
                  android:icon="@drawable/ic_search"
                  app:showAsAction="ifRoom"
                  ></item>
              <item
                  android:id="@+id/action_user"
                  android:orderInCategory="300"
                  android:title="User"
                  android:icon="@drawable/ic_user"
                  app:showAsAction="ifRoom"></item>
      
          </menu>
      

      【讨论】:

      • 我实现了这个,但它只是在抽屉内添加了更多列表项。我想要标题顶部的按钮。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-05-05
      • 1970-01-01
      • 2021-02-15
      • 2016-10-27
      • 2017-07-13
      • 1970-01-01
      • 2015-12-04
      相关资源
      最近更新 更多