【问题标题】:Elevation not working on android.support.design.widget.FloatingActionButton高程不适用于 android.support.design.widget.FloatingActionButton
【发布时间】:2015-08-24 17:07:16
【问题描述】:

我刚刚开始 android 开发并尝试新的材料设计。 是我的 mainactivity 的屏幕截图,它有一个 FloatingActionButton 但它没有应用任何高度(没有阴影)。

如何在这个新小部件 (android.support.widget.FloatingActionButton) 上启用阴影。

这是布局xml中的代码

<android.support.design.widget.FloatingActionButton
        android:id="@+id/add_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:src="@drawable/ic_add_action"
        android:layout_margin="16dp"
        android:elevation="10dp"
        android:padding="10dp"/>

任何帮助表示赞赏。谢谢

请注意,我只想使用 android 设计库,而不是任何其他 github 库。

【问题讨论】:

    标签: android material-design floating-action-button


    【解决方案1】:

    经过大量研究,我找到了使用 FAB 的正确方法,没有任何问题。使用下面的代码作为模板:

    <android.support.design.widget.FloatingActionButton
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/your_id"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:layout_marginBottom="@dimen/floating_button_margin_bottom"
            android:layout_marginRight="@dimen/floating_button_margin_right"
            app:elevation="@dimen/floating_button_elevation"
            app:borderWidth="0dp"
            app:rippleColor="@color/your_ripple_color"
            app:backgroundTint="@color/your_bg_color" />
    

    【讨论】:

    • @dimen/floating_button_margin_bottom 的值是多少?
    • 需要添加的主要更改是什么?因为实际上它是行不通的。
    • app:borderWidth="0dp" 是@shadow-01 和@Anggrayudi H 所述的诀窍
    【解决方案2】:

    我现在只是在测试浮动操作按钮。对我来说它有效。

    尝试为您的按钮添加app:borderWidth="0dp",这可能会解决问题。 我在其他一些帖子中看到这可能是设计库中的问题。

    【讨论】:

      【解决方案3】:

      您的 XML 布局可能遗漏了这些代码:

      <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
         app:xmlns="http://schemas.android.com/apk/res-auto"
         ... >
               <android.support.design.widget.FloatingActionButton
                  ... 
                  app:borderWidth="0dp"
                  app:elevation="4dp" />
         ... 
      </RelativeLayout>
      

      编辑

      有关FloatingActionButton 的更多信息,请参阅此post,其中解释了问题和设计指南。

      【讨论】:

        【解决方案4】:

        检查清单文件并删除下一个属性:

         android:hardwareAccelerated="false"
         android:largeHeap="true"
        

        【讨论】:

          猜你喜欢
          • 2018-03-15
          • 2019-04-17
          • 2010-09-15
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-01-03
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多