Reputation: 994
I am using a SeekBar in my layout and I have another View that is a RelativeLayout.
<CoordinatorLayout>
<RelativeLayout>
...
</RelativeLayout>
<SeekBar
android:id="@+id/progressSeekBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:progress="70"
android:progressDrawable="@drawable/player_seek_bar_progress"/>
</CoordinatorLayout>
And when I touch this RelativeLayout, the SeekBar gains the focus... I don't find any problem in my layout even in my code...
Does someone have the same issue?
Thanks guys for your answers :)
Upvotes: 2
Views: 2633
Reputation: 371
i have seekBar inside my frameLayout i have done this programatically & it worked for me :
seekbar.isClickable = true
Upvotes: 0
Reputation: 31
Simply set android:clickable="true"
and android:focusable="true"
as a SeekBar XML attributes. After doing so the SeekBar will not get focus when you click on parent layout.
Credits to @Kashmir
<SeekBar
android:id="@+id/seekBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
/>
Upvotes: 0
Reputation: 146
Just put this in root view and remove any clickable in root
android:descendantFocusability="blocksDescendants"
Upvotes: 0
Reputation: 242
I've just had the exact same problem.
My layout looks something like the following (I omitted irrelevant views for this topic). As you can see, both the parent view (the LinearLayout
) and the SeekBar
have android:clickable="true"
property.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:clickable="true"
android:layout_width="match_parent"
android:layout_height="match_parent">
<SeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true" />
</LinearLayout>
Here's what I've found in the source code for #android.view.ViewGroup#dispatchSetPressed
(this is the event that gets called each time the user touches the screen)
It loops through every child view, and if it matches the following condition, it propagates the event to this child view:
if (!pressed || (!child.isClickable() && !child.isLongClickable())) {
child.setPressed(pressed);
}
Basically, if your child view (in this case, the SeekBar
is either clickable or long clickable, you will not propagate the event to it.
In addition, there's a comment that says the following:
Children that are clickable on their own should not show a pressed state when their parent view does. Clearing a pressed state always propagates.
The situation this comment is describing is the same as you are facing right now. If you set the SeekBar
as clickable, Android knows that is has to react to click events directly in the SeekBar
, and it will not propagate the event.
This worked for me. Hope it will work for you too.
Upvotes: 7
Reputation: 321
mSeekBar = (SeekBar) v.findViewById(R.id.progressSeekBar);
mSeekBar.setFocusable(false);
Have you tried programmatically setting your SeekBar? This seemed to work for me, but setting the XML attribute to android:focusable="false"
did not.
Upvotes: 0
Reputation: 30985
<SeekBar
android:id="@+id/progressSeekBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:progress="70"
android:progressDrawable="@drawable/player_seek_bar_progress"
android:focusable="false"/>
Upvotes: 0