Android 可点击布局
我有一个线性布局,我已将其设置为 true 可点击 + 焦点,但问题是单击时没有显示焦点。我怎样才能让焦点显示出来。
这是我的代码
<LinearLayout
android:id="@+id/linear_tv_layout"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:clickable="true"
android:focusable="true"
android:paddingBottom="7px">
I've got a linear layout that i have set true to be clikable + focus, But the problem is there is no focus displayed when clicked. How can i get the focus to be displayed.
Heres my code
<LinearLayout
android:id="@+id/linear_tv_layout"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:clickable="true"
android:focusable="true"
android:paddingBottom="7px">
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
将 Material Design 的按钮按下动画应用于任何元素,将元素的 android 背景属性设置为:
在您的情况下:
To apply material design's button press animation to any element, set the element's android background attribute to:
In your case:
我认为您需要将 状态列表drawable,它是一种drawable资源,你可以为不同的状态或状态组合指定不同的drawable,有一个用于选择,一个用于压缩等等。此外,布局的状态会传播到其所有子布局。
澄清 - 这是之前链接的文档中的示例:
res/drawable/button.xml:
(它是可绘制的状态列表)button_pressed
、button_focused
和button_normal
是代表这些状态下按钮的普通可绘制对象,可能是 png 的(因此按下的可以是插图,聚焦以橙色突出显示)。如果您将此资源设置为“线性布局按钮”的背景:
现在聚焦布局将自动将其背景图像设置为
@drawable/button_focused
,依此类推。当然,您使用的所有可绘制对象都必须已经是
res/drawable/
中的资源,以及button.xml
。I think you need to set as background for the clickable view (the layout) a state list drawable , it's a drawable resource for which you can specify different drawables for different states or combinations of states, there's one for selection, one for pression and so on. Also, the state of a layout propagates to all its children.
CLARIFICATIONS - this is the example from the previously linked docs:
res/drawable/button.xml :
(it's the state list drawable)button_pressed
,button_focused
andbutton_normal
are normal drawables representing the button in those states, probably png's (so pressed could be inset, focused highlighted in orange).if you set this resource as background to your "linear layout button":
now focusing the layout will automatically set its background image to
@drawable/button_focused
, and so on.of course, all the drawables you use must already be resources in
res/drawable/
, together withbutton.xml
.@丹莱昂:
而不是
android:background="@android:drawable/btn_default"
你应该使用
android:background="@android:drawable/list_selector_background"
前者也会修改 UI,但这不是必需的。
@danLeon:
Instead of
android:background="@android:drawable/btn_default"
you should use
android:background="@android:drawable/list_selector_background"
former will modify the UI as well, which is not required.
尝试在代码中将该布局置于前面:
如果这不起作用,请检查是否有一个或多个视图与该 LinearLayout 重叠。
Try to bring that layout to front in code:
If that does not work, check if there is one or more view overlapped over that LinearLayout.
这是一个示例布局,可能可以给您一些想法:
Heres a sample layout may be this can give you some idea:
一个简单的方法是设置此属性:
android:background="@android:drawable/btn_default"
A simple way is by setting this attribute:
android:background="@android:drawable/btn_default"