如何隐藏在搜索栏/显示拇指绘制 [英] How to hide/show thumb drawable in a SeekBar

查看:143
本文介绍了如何隐藏在搜索栏/显示拇指绘制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义绘制的拇指一个搜索栏,我想隐藏它基于另一个控制我必须要能够显示/。

I have a SeekBar with a custom drawable for the Thumb, and I would like to be able to show/hide it based on another control I have.

我试图加载从资源的绘制,然后使用SeekBar.setThumb()与绘制,或者为null。

I have tried loading the drawable from resources, and then using SeekBar.setThumb() with the drawable, or null.

这是隐藏它(设置为null),但我永远不能拿回来。

That hides it (the set to null), but I can never get it back.

推荐答案

要做到这一点,最好的方法是设置可绘制从XML拇指(因为我是做所有沿),然后当你想隐藏/显示拇指绘制,只需操纵它的alpha值:

The best way to do this is to set the drawable for the thumb from XML (as I was doing all along) and then when you want to hide/show the Thumb drawable, just manipulate it's alpha value:

// Hide the thumb drawable if the SeekBar is disabled
if (enabled) {
    seekBar.getThumb().mutate().setAlpha(255);
} else {
    seekBar.getThumb().mutate().setAlpha(0);
}

这篇关于如何隐藏在搜索栏/显示拇指绘制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆