带有图像和文本的 Android 选择器 [英] Android selector with image and text

查看:52
本文介绍了带有图像和文本的 Android 选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个按钮,可以像这样提供颜色、图像和文本:

I have a button which I give a color, image and text like this:

android:background="@color/green"
android:drawableLeft="@drawable/custom_routes_start_button_icon"
android:text="@string/custom_route_start"

这是未选中的状态,希望选中的状态是这样的:

This is the unselected state and want the selected state to be something like this:

android:background="@color/red"
android:drawableLeft="@drawable/custom_routes_stop_button_icon"
android:text="@string/custom_route_stop"

据我所知,不可能在选择器中为项目提供文本或 drawableLeft(仅可绘制).有人知道实现这一目标的好方法吗?也许另一个 xml 文件可供 te 选择器也可以引用?

For all I know its not possible to give an item in selector a text or drawableLeft (only drawable). Does anybody know a nice way to achieve this? Maybe another xml file where te selector could refer too?

推荐答案

您应该使用两个按钮,并且只显示其中一个.使用 XML 中的 android:visibilitysetVisibility() 来显示/隐藏按钮.

You should use two Buttons and only ever show one of them. Use android:visibility in XML and setVisibility() to show/hide the buttons.

因此,首先使开始按钮可见并隐藏停止按钮.当用户按下开始按钮时,隐藏开始按钮并显示停止按钮.当用户按下停止按钮时,隐藏它并再次显示开始按钮.

So, at first make the start button visible and hide the stop button. When the user presses the start button, hide the start button and show the stop button. When the user presses the stop button, hide it and show the start button again.

这篇关于带有图像和文本的 Android 选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆