温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

TextView设置文本选中颜色

发布时间:2024-08-21 14:15:18 来源:亿速云 阅读:80 作者:小樊 栏目:移动开发

要设置TextView文本选中颜色,可以通过设置TextView的textColorHighlight属性来实现。以下是一个示例代码:

<TextView
    android:id="@+id/textView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hello, World!"
    android:textColor="@color/text_color"
    android:textColorHighlight="@color/text_color_highlight"
    />

在上面的代码中,我们设置了TextView的textColor属性来指定文本的颜色,同时设置了textColorHighlight属性来指定文本选中时的颜色。你可以在res/values/colors.xml文件中定义颜色值:

<color name="text_color">#000000</color>
<color name="text_color_highlight">#FF0000</color>

通过以上代码,当用户选中文本时,文本的颜色将会变为红色。你也可以根据自己的需求修改颜色值来实现不同的效果。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI