【问题标题】:How to get Text color in Button to be like App background?如何让 Button 中的文本颜色像 App 背景一样?
【发布时间】:2020-03-31 00:36:33
【问题描述】:

我最近在 Android Studio 中为一件事而苦苦挣扎。我不知道如何设置(或者是否有可能)按钮中的文本与 Activity 中的背景具有相同的颜色(或根本没有颜色)。我的意思是说: I want this white text in black button to be the same color as App background (gradient)

按钮 XML:

<Button
                android:id="@+id/startButton"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="90dp"
                android:background="@drawable/button"
                android:fontFamily="@font/amiko"
                android:text="START"
                android:textColor="#ffffff"
                android:textStyle="bold" />

按钮形状 XML:

<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="rectangle"
xmlns:android="http://schemas.android.com/apk/res/android">


<solid android:color="#000000"/>

    <corners android:radius="30dp" />


</shape>

我尝试将 Button 中的文本颜色设置为透明,但它变成了黑色,就像按钮颜色一样。

【问题讨论】:

    标签: android xml android-studio


    【解决方案1】:

    您可以使用透明色作为 Button 的背景色。只需将按钮形状 XML 颜色修复为此值:#00000000。前 2 个值代表 Alpha 通道,通过这个额外的 00,您可以将颜色设置为透明。

    按钮形状 XML:

    <?xml version="1.0" encoding="utf-8"?>
    <shape android:shape="rectangle"
        xmlns:android="http://schemas.android.com/apk/res/android">
    
    
        <solid android:color="#00000000"/>
    
        <corners android:radius="30dp" />
    
    </shape>
    

    【讨论】:

    • 你误解了我的问题。我想让我的按钮中的文本透明,而不是这个形状。如果我按照您阅读的方式进行操作,我的整个按钮(文本除外)都会消失。
    猜你喜欢
    • 1970-01-01
    • 2011-07-02
    • 2010-10-20
    • 2019-09-28
    • 1970-01-01
    • 2020-01-25
    • 1970-01-01
    • 1970-01-01
    • 2014-07-25
    相关资源
    最近更新 更多