【问题标题】:How to remove the default indicator icon of a seekbar [android] which has been set a custom progress drawable如何删除已设置自定义进度可绘制的搜索栏 [android] 的默认指示器图标
【发布时间】:2017-12-28 15:14:12
【问题描述】:

请找到我正在尝试实现的自定义搜索栏的以下屏幕截图。

我非常接近构建如上所示的搜索栏(搜索栏下方没有图像)。下面是我所做的截图。

问题:

正如您在第二个屏幕截图中看到的,在搜索栏中的进度指示器栏之后有一个图标。我一直试图摆脱它,但显然没有成功。有关如何删除该图标的任何建议/想法都会有很大帮助。谢谢。

SeekBar 布局 XML

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.application.todo.activityTransition.activities.SeekBarActivity">

<TextView
    android:id="@+id/painLevelText"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:padding="10dp"
    android:text="@string/painLevelText" />

<LinearLayout
    android:id="@+id/radIoGroupLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/painLevelText"
    android:orientation="vertical">

    <RadioGroup
        android:id="@+id/seekBarRadioGroup"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="10">

        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1" />

        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1" />

        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1" />

        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1" />

        <RadioButton
            android:id="@+id/defaultSelection"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1" />

        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1" />

        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1" />

        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1" />

        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1" />

        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1" />
    </RadioGroup>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:orientation="horizontal"
        android:weightSum="10">

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="1" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="2" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="3" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="4" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="5" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="6" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="7" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="8" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="9" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="10" />

    </LinearLayout>

</LinearLayout>

<RelativeLayout
    android:id="@+id/seekBarLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/radIoGroupLayout"
    android:background="@drawable/seekbar_layout_background">

    <SeekBar
        android:id="@+id/seekBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:max="10"
        android:progress="5"
        android:progressDrawable="@drawable/custom_seek_bar" />

    <TextView
        android:id="@+id/seekBarProgressValue"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:gravity="center"
        android:padding="10dp"
        android:textColor="#FFF"
        android:textSize="15sp" />
</RelativeLayout>


</RelativeLayout>

用于搜索栏的自定义可绘制文件

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/progress">
    <clip>
        <shape android:shape="rectangle">
            <size
                android:width="12dp"
                android:height="12dp" />
            <corners android:radius="15dp" />

            <solid android:color="#FF8D1E" />

            <gradient
                android:angle="270"
                android:centerColor="#FF8D1E"
                android:endColor="#FF971F"
                android:startColor="#FF971F" />
        </shape>
    </clip>
</item>
</layer-list>

请在答案部分找到我的答案

【问题讨论】:

标签: android android-seekbar


【解决方案1】:

这个link 有助于实现预期的结果。但是我在使用下面的代码行时发现了一个问题

seekBar.getThumb().mutate().setAlpha(0);

它确实在最后删除了拇指,但是当我们从无线电组中选择“10”时,进度指示器被砍掉了。下面是相关图片。

但是当我在布局中将此 XML 标记用于搜索栏时,它按预期工作。

android:thumb="@null"

图片

不确定这是否是正确的方法,但确实成功了。

【讨论】:

  • 嗨 Itapu,你能发布你的完整代码,类文件,你是如何实现的。我也有同样的要求。
【解决方案2】:

只需将此行放在您的 Seekbar xml 代码中即可。..

          android:thumbTint="@android:color/transparent"

【讨论】:

    【解决方案3】:

    试试这个

    android:splitTrack="false"
    seekbar.getThumb().mutate().setAlpha(0);
    

    【讨论】:

      【解决方案4】:

      我认为SeekBar 不是您的用例的正确实现。尝试改用ProgressBar,这样就不用担心拇指了。

      【讨论】:

      • 嗨,肯特,感谢您抽出时间回复。您能否建议任何链接/参考资料,我可以在其中找到有关开始实施进度条的信息?
      • 只需在 XML 布局和活动/片段中将 SeekBar 替换为 ProgressBar,就可以了。
      • 它不工作。我已将搜索栏更改为进度条(在 XML 以及活动中的相关代码中)。进度条不可见。下面是对 xml 所做的更改。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-08
      • 1970-01-01
      • 2015-09-12
      相关资源
      最近更新 更多