首页 > 解决方案 > 如何在 Android 中制作像这样的自定义搜索栏?

问题描述

我如何设计自定义seekbar下面的图像

自定义搜索栏 1

自定义搜索栏 2

有没有人有想法请指导我。提前感谢大家

标签: androidandroid-seekbar

解决方案


我认为这个图书馆会帮助你

- 将以下依赖项添加到您的 build.gradle 文件中。

    implementation'com.kevalpatel2106:ruler-picker:1.1'

- 在您的 XML 布局中添加 RulerValuePicker。

<com.kevalpatel2106.rulerpicker.RulerValuePicker
    android:id="@+id/ruler_picker"
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:background="@android:color/holo_orange_dark"
    app:indicator_color="@android:color/white"
    app:indicator_interval="14dp"
    app:indicator_width="2dp"
    app:max_value="120"
    app:min_value="35"
    app:notch_color="@android:color/white"
    app:ruler_text_size="6sp"/>

- 爪哇:

rulerValuePicker.setValuePickerListener(new RulerValuePickerListener() {
    @Override
    public void onValueChange(final int selectedValue) {
        //Value changed and the user stopped scrolling the ruler.
        //Application can consider this value as final selected value.
    }

    @Override
    public void onIntermediateValueChange(final int selectedValue) {
        //Value changed but the user is still scrolling the ruler.
        //This value is not final value. Application can utilize this value to display the current selected value.
    }
});

- 科特林:

rulerValuePicker.setValuePickerListener(object : RulerValuePickerListener {
    override fun onValueChange(value: Int) {
        //Value changed and the user stopped scrolling the ruler.
        //You can consider this value as final selected value.
    }

    override fun onIntermediateValueChange(selectedValue: Int) {
        //Value changed but the user is still scrolling the ruler.
        //This value is not final value. You can utilize this value to display the current selected value.
    }
})

- 截图:

在此处输入图像描述 在此处输入图像描述


推荐阅读