gpt4 book ai didi

android - 按钮背景为透明

转载 作者:IT老高 更新时间:2023-10-28 12:55:19 25 4
gpt4 key购买 nike

我有一个按钮。当我按下按钮时,我必须将文本设置为粗体,否则正常。所以我写了粗体和正常的样式。

<style name="textbold" parent="@android:style/TextAppearance">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textStyle">bold</item>
</style>
<style name="textregular" parent="@android:style/TextAppearance">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textStyle">normal</item>
</style>

现在我有一个 button_states.xml 为:

<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:state_pressed="true"
style="@style/textbold" />
<item android:state_focused="false" android:state_pressed="true"
style="@style/textregular" />

<item style="@style/textregular" />
</selector>

在此按钮的布局中,我还必须将背景设置为透明...我该怎么做?我的布局代码是:

<Button android:id="@+id/Btn" android:background="@drawable/button_states" />

如何在我的样式中包含透明背景?

最佳答案

要使背景透明,只需执行 android:background="@android:color/transparent" .

但是,您的问题似乎有点深,因为您以一种非常奇怪的方式使用选择器。您使用它的方式似乎是错误的,但如果它确实有效,您应该将背景图像作为 <item/> 放入样式中。 .

仔细查看 Android 源代码中如何使用样式。虽然它们不会在单击按钮时更改文本样式,但有很多关于如何实现目标的好主意。

关于android - 按钮背景为透明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4954102/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com