[英]Floating Button Not Taking Background Color
我的主要活动中有一个浮动按钮,该按钮从应用程序主题colorAccent设置中获取颜色。 我想更改它。 因此,我将背景色设置为一个圆形的矢量图像。 但是,它没有生效。 如何强制它对绿色的colorPrimaryDark生效。
<?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.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/MyToolbarStyle">
<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" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:src="@drawable/ic_next_button"
android:background="@drawable/round_button"
android:layout_margin="10dp" />
</android.support.design.widget.CoordinatorLayout>
round_button
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<size android:height="50dp" android:width="50dp"/>
<solid android:color="@color/colorPrimary"/>
<corners android:radius="30dp"/>
</shape>
尝试这个
对于图标:
android:src="@android:drawable/ic_menu_add"
对于背景色:
app:borderWidth="0dp"
app:backgroundTint="@color/colorPrimary"
用这个
<android.support.design.widget.FloatingActionButton
...
app:backgroundTint="@color/yourcolor"
app:borderWidth="0dp"
/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.