我是刚进Android Studio的人。只是阅读和学习有关梯度的用法。浮动按钮是否可以使用渐变颜色来填充整个形状?同样,是否可以使用渐变色创建文本视图样式?
当然创建一个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>
感谢您的回答。但是可以仅使用colorAccent还是可以指示其他颜色?在我的代码中,我试图只使用颜色,并期望它用颜色覆盖所有浮动按钮,但是中间只有正方形。
我想实现的是渐变背景上的浮动按钮(带有加号的内部或箭头,喜欢向前和向后移动。)>
我用这样的背景色来描述:
<?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>
我做错了什么?