android - 搜索栏的自定义布局或设计

标签 android android-layout android-custom-view android-seekbar

有没有办法自定义搜索栏的外观,以便我可以为搜索栏(缩略图、轨道和进度)放置我自己的设计/图像。我看过这篇文章,但链接已损坏。

How to create custom layout for seekbar in android?

谢谢

最佳答案

这可能会有所帮助 custom seekbar ,您可以更改您想要的内容(缩略图、跟踪和进度,以及更多有用的东西),但只能通过编程方式进行。我为这个库做出了贡献,唯一的问题是这个搜索栏是一个范围搜索栏,但是你可以 fork 这个 repo 并添加功能以启用范围或不启用范围并删除其中一个拇指。

实现这一点的最快方法是注释 RangeSeekBar.java 中的第 498 行(但您只会影响拇指仍然对拖动使用react的“可见性”,您必须编写更多代码^^)

// draw minimum thumb
drawThumb(normalizedToScreen(mNormalizedMinValue), Thumb.MIN.equals(mPressedThumb), canvas);

然后在您的 Activity 中,您将使用 maxValue:

mSeekBar.setOnRangeSeekBarChangeListener(new RangeSeekBar.OnRangeSeekBarChangeListener<Integer>() {
    @Override
    public void onRangeSeekBarValuesChanged(RangeSeekBar<?> bar, Integer minValue, Integer maxValue) {
        ...
        }
    });

下面是一个关于如何自定义 seekBar 的示例:

mSeekBar.setNotifyWhileDragging(true);
mSeekBar.setThumbImage(BitmapFactory.decodeResource(getResources(), R.drawable.seek_thumb_normal));
mSeekBar.setProgressBackgroundColor(0xFF, 0xDD, 0xDD, 0xDD);
mSeekBar.setProgressLineColor(0xFF, 0xE8, 0x4E, 0x44);
mSeekBar.setMaxHeight(Utils.convertDpToPx(getActivity(), 2));

enter image description here enter image description here

或者你使用 Android 布局配置:

<SeekBar
          ...
          android:progressDrawable="@drawable/seekbar_default_progress"
          android:thumb="@drawable/seek_thumb"/>

<item android:id="@android:id/progress">
    <clip android:drawable="@color/some_color"/>
</item>

关于android - 搜索栏的自定义布局或设计,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35327011/

相关文章:

android - Google play服务认证(oauth 2.0)

java - 将 firebase 数据检索为 json

Android Webview rem 单位可缩放到盒子的大尺寸

java - Android 布局编辑器中的 NotFoundException?

android - Android TabHost 上的徽章

android - 无法安装应用程序 : SHELL_UNRESPONSIVE -android studio 3. 5

android - TextView在OpenGl curl View 效果上不可点击

android - 部分不可编辑的多行编辑文本,例如填空

java - 如何将 View 放在确切的列和行中并使其填充该列 GridLayout android

Android:如何使用可见性 GONE 对象的空间?