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">
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.
To apply material design's button press animation to any element, set the element's android background attribute to:
In your case:
Heres a sample layout may be this can give you some idea:
@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.
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
.A simple way is by setting this attribute:
android:background="@android:drawable/btn_default"