1

我是android工作室的新人。只是阅读和研究梯度的使用。是否可以为浮动按钮使用渐变颜色来填充整个形状?同样,是否可以使用渐变颜色创建文本视图样式?

4

2 回答 2

0

当然创建一个 background.xml 可绘制文件夹并在下面编写代码

<?xml version="1.0" encoding="utf-8"?>
   <shape>
           <gradient android:startColor="@color/colorAccent"
               android:centerColor="@color/colorAccent"
               android:endColor="@color/black"
                android:angle="90"/>
            <corners android:radius="10dp"></corners>
        </shape>
于 2020-05-09T22:55:11.923 回答
0

Thanks for the answer. But is it possible to use only colorAccent or is it possible to indicate other colors? In my code, I was trying to use just colours and was expecting it to cover all the floating button with the colour, but I have it only like square in the middle. enter image description here

What I want to achieve is floating buttons (either with plus side inside or arrows, like to go back and forward) on the gradient background.

I describe by background colour like this:

    <?xml version="1.0" encoding="utf-8"?>
         <shape xmlns:android="http://schemas.android.com/apk/res/android"
             android:shape="oval">
              <gradient
                  android:angle="270"
                  android:startColor="#A70797"
                  android:endColor="#0723B5"
             />
         </shape>

Then from floating action buttons, I selected the icon ic_menu_add

Actual floating action button is described like this



    <com.google.android.material.floatingactionbutton.FloatingActionButton
            android:id="@+id/fab_1"
            style="@style/Myfbutton"
            android:focusable="true"
            app:fabSize="mini"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:srcCompat="@drawable/fback" />

    For style I have

    <style name="Myfbutton">Myfbutton
            <item name="android:shape">oval</item>item>
            <item name="android:layout_width">42dp</item>
            <item name="android:layout_height">42dp</item>
            <item name="android:clickable">true</item>
            <item name="android:layout_margin">16sp</item>
    </style>

What I am doing wrong?

于 2020-05-10T09:33:39.500 回答