我正在尝试自定义搜索栏,但它不起作用

时间:2017-12-15 20:27:29

标签: android android-layout

我有想要构建的搜索栏的这个图像: enter image description here

但我的搜索栏看起来像这样:

enter image description here

我的搜索栏没有透明度,我不能让它更薄。 我怎么能这样做?

以下是代码: 搜索条:

                <SeekBar
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:alpha="0.75"
                    android:max="25"
                    android:min="7"
                    android:progress="1"
                    android:splitTrack="false"
                    android:progressDrawable="@drawable/progress_seek_bar_settings"
                    android:thumb="@drawable/thumb_seekbar_settins" />

拇指:

<?xml version="1.0" encoding="utf-8"?>

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

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

            <solid android:color="@color/color_primary_dark" />
        </shape>
    </item>
</layer-list>

进度:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@android:id/background">
        <shape>
            <gradient
                android:startColor="@color/color_primary"
                android:endColor="@color/color_primary"/>
            <size
                android:width="1dp"
                android:height="2dp"
                 />
            <corners android:radius="3dp" />
        </shape>
    </item>
    <item android:id="@android:id/progress">
        <clip>
            <shape>
                <gradient
                    android:startColor="@color/color_primary"
                    android:endColor="@color/color_primary" />
                <size
                    android:width="1dp"
                    android:height="2dp"
                    />
                <corners android:radius="3dp" />
            </shape>
        </clip>
    </item>
</layer-list>

我需要帮助尽可能接近第一张图片。谢谢!!

1 个答案:

答案 0 :(得分:0)

你好 drawable / progress_seek_bar_settings 转换

<item android:id="@android:id/background">

<item android:id="@android:id/background"
      android:height="3dp"
      android:gravity="center_vertical"
    >

<强>更新

抽拉/ thumb_seekbar_settins.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
        <shape android:shape="oval">
            <size
                android:height="20dp"
                android:width="20dp" />
            <solid android:color="#ebeb" />
        </shape>
    </item>
</layer-list>

抽拉/ progress_seek_bar_settings.xml

<?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:height="3dp"
        android:gravity="center_vertical"
        >
        <shape>
            <gradient
                android:startColor="#ebeb"
                android:endColor="#ebeb"/>
            <size
                android:width="1dp"
                android:height="2dp"
                />
            <corners android:radius="3dp" />
        </shape>
    </item>
    <item android:id="@android:id/progress"
        android:height="3dp"
          android:gravity="center_vertical"
        >
        <clip>
            <shape>
                <gradient
                    android:startColor="#ebeb"
                    android:endColor="#ebeb" />
                <size
                    android:width="1dp"
                    android:height="2dp"
                    />
                <corners android:radius="3dp" />
            </shape>
        </clip>
    </item>

</layer-list>

活性

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingTop="40dp"
    android:background="@android:color/black"
    >
    <SeekBar
        android:layout_marginTop="40dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:alpha="0.75"
        android:max="100"
        android:min="7"
        android:progress="1"
        android:splitTrack="false"
        android:progressDrawable="@drawable/progress_seek_bar_settings"
        android:thumb="@drawable/thumb_seekbar_settins" />
</android.support.constraint.ConstraintLayout>

看起来像这样:

enter image description here