Android版:聚焦时,改文风 [英] Android: change style when focused
问题描述
我有这样的自定义布局:
I have this custom layout:
- LinearLayout
- FrameLayout
- ImageView
- TextView
此布局反应click事件(使用 LinearLayout.setOnClickListener()
),并使用机器人是由可聚焦:聚焦的=真正的
布局XML文件英寸这一切工作正常,如果你使用触摸屏,但我想谁不使用那么多和preFER导航键或者甚至没有触摸屏触摸屏的用户。这些用户将无法看到当的ViewGroup
的重点是(虽然它的可以使用键盘聚焦)。
This layout reacts to click events (using LinearLayout.setOnClickListener()
) and is made focusable using android:focusable="true"
in the layout XML file. This all works fine if you're using the touchscreen, but I'm thinking about users who don't use the touchscreen that much and prefer navigation keys or maybe even don't have a touchscreen. These users won't be able to see when that ViewGroup
is focused (although it can be focused using the keyboard).
我的问题是:如何才能让在布局发生变化时,它的重点是(我需要改变的android:背景
的 ImageView的
)?我想我可以使用 LinearLayout.setOnFocusChangeListener()
,但我想也许有更好的方法,只使用XML文件。
My question is: how can I make a change in that layout when it is focused (I need to change the android:background
of the ImageView
)? I suppose I could use LinearLayout.setOnFocusChangeListener()
, but I'm thinking maybe there's a better way, using just XML files.
推荐答案
给的东西(的LinearLayout
?)的背景图像这是一个 StateListDrawable
(XML绘制与<选择>
根元素)。也许只用一个透明的颜色,正常的情况下,但使用的安卓别的东西:集中=真正的
情况。然后,当它获得焦点,后台会自动更改。
Give something (LinearLayout
?) a background image that is a StateListDrawable
(drawable XML with <selector>
root element). Perhaps use just a transparent color for the normal case, but use something else for the android:focused="true"
case. Then, when it gets the focus, the background will change automatically.
这篇关于Android版:聚焦时,改文风的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!