【问题标题】:Gradient usage in android studioandroid studio中的渐变使用
【发布时间】:2020-08-25 12:27:45
【问题描述】:

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

【问题讨论】:

  • 是的,您可以在每个位置应用渐变。那么你想要哪种类型的渐变,在哪里呢?
  • 根据下面的答案,我想将其中一个位置作为浮动操作按钮的背景色,复制了我的代码。
  • 你知道你想要在 FAB 中使用哪种类型的渐变吗?任何资源
  • 基本上,我希望按钮带有渐变色(就像按钮里面带有加号,或者带有箭头来回和前进)
  • 我这样描述背景颜色:schemas.android.com/apk/res/android" android:shape="oval "> 然后从浮动操作按钮中,我选择了图标 ic_menu_add 实际浮动操作按钮描述像这样

标签: android-studio gradient floating-action-button textstyle


【解决方案1】:

当然要创建一个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>

【讨论】:

    【解决方案2】:

    感谢您的回答。但是可以只使用 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>
    

    我做错了什么?

    【讨论】:

    猜你喜欢
    • 2021-04-17
    • 2020-08-27
    • 1970-01-01
    • 2015-05-27
    • 1970-01-01
    • 2011-01-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多