当前位置: 首页 > 知识库问答 >
问题:

设置晶圆厂图标颜色

华星文
2023-03-14

我想知道如何改变由'com.android.support:design:22.2.0'库提供的FAB(浮动操作按钮)小部件的图标颜色从绿色到白色。

style.xml

<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/color_primary</item>
    <item name="colorPrimaryDark">@color/color_primary_dark</item>
    <item name="colorAccent">@color/accent</item>

</style>
<color name="color_primary">#00B33C</color>
<color name="color_primary_dark">#006622</color>
<color name="accent">#FFB366</color>

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

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

    <TextView android:id="@+id/text"
        android:text="@string/hello_world"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="16dp"
        android:paddingTop="16dp"
        android:textSize="20sp" />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:scrollbars="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingLeft="8dp"
        android:paddingRight="8dp"
        android:paddingTop="8dp"
        android:paddingBottom="16dp" />

</LinearLayout>

<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="@android:drawable/ic_input_add"
    android:layout_margin="24dp"
    app:elevation="6dp"
    app:pressedTranslationZ="12dp"
    app:borderWidth="0dp" />

共有1个答案

那弘
2023-03-14

使用Android:tint属性,您可以如下所示设置颜色

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:tint="@android:color/white"
    android:src="@android:drawable/ic_input_add"
   />
 类似资料:
  • 在Android中,我想做这样的事情(但是有两种交替的颜色:黑色和白色: 像这样用波纹效果改变颜色 我试着做的是: 1)通过XML设置默认背景色和波纹色 2)在onclick方法中,将背景色改为白色,将波纹色改为黑色 有没有办法让这个看起来像第一个?比如放慢波纹动画速度之类的?

  • 我有一个带有CardView和禁用的的布局,我以编程方式将其设置为enabled,当FAB被启用时,所有工作都很好,但当我将其设置为disabled时,它会在卡后面。 我已经试着通过设置一个更高的高度来设置卡片和晶圆厂的高度,但是当它被禁用的时候,它仍然会高于… 下面是它的样子: 我将显示它的重叠,就像当enabled设置为true时: 下面是我的代码:

  • 我在android中使用FAB,我增加了Src图像大小来覆盖FAB,但现在每当我点击FAB时,涟漪效应会显示在图像后面,而不是上面,这不会给人一种FAB被点击的感觉 我的晶圆厂代码

  • 在我的所有布局中,如果用户将手指伸出FAB视图,我的FloatingActionButtons的涟漪效果将持续存在。也就是说,用户按下白色晶圆厂,波纹发生,晶圆厂变成灰色,用户将手指从按钮上拖开并举起,按钮保持灰色。 所有的晶圆厂都是不同的基本坐标布局的直接子代,即。 在从Android5.1到Android7.1的各种设备上测试,每个设备上都有相同的问题。 我没有在我的其他视图上看到任何类似的情