gpt4 book ai didi

android - 使用选择器使 TextView 变粗

转载 作者:行者123 更新时间:2023-11-30 02:49:48 25 4
gpt4 key购买 nike

当用户按下我的 TextView 时,我想将 TextView 设为粗体。这就是我正在尝试的:

// styles.xml
<style name="TextOn">
<item name="android:textStyle">bold</item>
</style>

<style name="TextOff">
<item name="android:textStyle">normal</item>
</style>


// my_selector.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/TextOn" />
<item android:state_focused="false" android:state_pressed="true" style="@style/TextOn" />
<item android:state_focused="true" style="@style/TextOn" />
<item android:state_focused="false" android:state_pressed="false" style="@style/TextOff" />
</selector>


// my textview in a layout
<TextView
...
android:duplicateParentState="true"
android:textAppearance="@drawable/my_selector" />

将textAppearance 设置为selector drawable 似乎不对,事实上,它没有任何效果。我们如何做到这一点?

谢谢

最佳答案

将选择器应用于样式仅适用于颜色和可绘制对象。请在下面的帖子中查看答案。

How to define bold in an Android selector

关于android - 使用选择器使 TextView 变粗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24389154/

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