Remove SeekBar shadow

╄→尐↘猪︶ㄣ 提交于 2020-02-05 06:58:31

问题


I'm getting a random shadow behind my SeekBar and thumb for some strange reason (the dark but not the black part). How do I get rid of it?

My SeekBar:

<SeekBar android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/slider"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:max="10"
    android:thumb="@drawable/thumb"
    android:progressDrawable="@drawable/progress_appearance"/>

thumb.xml

<?xml version="1.0" encoding="UTF-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

<gradient
    android:startColor="#ffffffff"
    android:endColor="#ffffffff"/>

<size android:height="20dp" android:width="20dp"/>
</shape>

progress_appearance.xml (has some weird gradient that I haven't removed yet)

<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<item android:id="@android:id/background"
    android:paddingTop="3px"
    android:paddingBottom="3px">
    <shape>
        <corners android:radius="100dip" />
        <gradient
            android:startColor="#000"
            android:centerColor="#000"
            android:endColor="#000"
            android:centerY="0.2"
            android:angle="270"/>
    </shape>
</item>

<item android:id="@android:id/progress">
    <clip>
        <shape>
            <corners android:radius="0dip" />
            <gradient
                android:startColor="#000"
                android:centerColor="#000"
                android:endColor="#000"/>
        </shape>
    </clip>
</item>
</layer-list>

回答1:


Try this:

    <SeekBar android:layout_width="fill_parent"
        android:layout_height="wrap_content"
/////
        android:background="@null"
/////
        android:id="@+id/slider"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:max="10"
        android:thumb="@drawable/thumb"
        android:progressDrawable="@drawable/progress_appearance"/>



回答2:


I used this code:

<SeekBar
    android:id="@+id/seekbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:max="100"
    android:background="@null"
    android:padding="0dp"
    android:progressDrawable="@drawable/progress_seekbar"
    android:thumb="@android:color/transparent" />

It worked for me.




回答3:


I was facing a similar problem.
After some struggling, I figured out that the shadow doesn't appear when it has something behind it.
So I finally put a white FrameLayout behind SeekBar.

Here's my code.

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent">

<!-- Putting this FrameLayout, I could remove the shadow. -->
<FrameLayout
    android:background="@android:color/white"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="70dp">
        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <!-- Thumbnail frames you see above -->
            <ImageView
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"/>
            ...
        </LinearLayout>

        <!-- The SeekBar -->
        <SeekBar
            android:padding="0dp"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
        ...

It is very weird because, I didn't put anything front of the shadow but behind the shadow.
I think this is Android's bug.

I hope it helps you :)




回答4:


Add this property in Seekbar

android:splitTrack="false"


来源:https://stackoverflow.com/questions/30310960/remove-seekbar-shadow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!