Child Clickable/parent Longclickable
I have a FrameLayout
with TextView
in it.
<FrameLayout
android:id="@+id/fl_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/selectableItemBackground">
<TextView
android:id="@+id/tv_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:linksClickable="true"
android:autoLink="email|web|phone"/>
</FrameLayout>
My TextView
has autoLink enabled for email/web/phone, as you can see. But my FrameLayout
has LongClickListener
in code.
flContainer.setOnLongClickListener {
// some work
}
But when I try to longtap to parent FL though the child TextView, it doesn't work, because TV intercepts click and doesn't allow parent to get longclick.
I know the simple solution - just apply the same longClickListener to TextView, but I have android:background="?attr/selectableItemBackground"
on my FL, so it should have ripple effect when I click it, but TV consumes it. Is it possible to achieve this?
Answer
Use android:addStatesFromChildren="true"
in your parent layout. As mentioned in the documentation,
Sets whether this ViewGroup's drawable states also include its children's drawable states. This is used, for example, to make a group appear to be focused when its child EditText or button is focused.
You can find about it here:
Related Questions
- → should I choose reactjs+f7 or f7+vue.js?
- → Phonegap Android write to sd card
- → Local reference jquery script in nanohttpd (Android)
- → Click to navigate on mobile devices
- → How to allow api access to android or ios app only(laravel)?
- → Access the Camera and CameraRoll on Android using React Native?
- → React native change listening port
- → What is the default unit of style in React Native?
- → Google play market autocomplete icon
- → Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of `ListView`
- → Using Laravel with Genymotion
- → react native using like web-based ajax function
- → react native pdf View