Java 禁用时如何使搜索杆变灰?
当我禁用它时,我想让灰色成为我的搜索杆。 我知道可以通过更改颜色以编程方式进行更改,但我想知道是否可以直接在xml活动布局中进行更改 事实上,在我的代码中,我只想写以下内容: mySeekBarNuance.setEnabled(true) 我的搜索杆会自动变灰。 谢谢像这样做 在您的styles.xml中Java 禁用时如何使搜索杆变灰?,java,android,seekbar,Java,Android,Seekbar,当我禁用它时,我想让灰色成为我的搜索杆。 我知道可以通过更改颜色以编程方式进行更改,但我想知道是否可以直接在xml活动布局中进行更改 事实上,在我的代码中,我只想写以下内容: mySeekBarNuance.setEnabled(true) 我的搜索杆会自动变灰。 谢谢像这样做 在您的styles.xml中 <style name="AppTheme" parent="Theme.AppCompat.DayNight.DarkActionBar"> // or the them
<style name="AppTheme" parent="Theme.AppCompat.DayNight.DarkActionBar"> // or the themw you are using
...
...
<item name="android:seekBarStyle">@style/MySeekBarStyle</item>
</style>
//或您正在使用的themw
...
...
@style/MySeekBarStyle
还添加了一个新样式
<style name="MySeekBarStyle" parent="android:Widget.SeekBar">
<item name="android:colorControlNormal">@color/gray</item> // put here the color for disable state
</style>
@颜色/灰色//将禁用状态的颜色放在此处
controlColorNormal
用于禁用状态,而colorAccent
用于启用状态
在您的styles.xml中
<style name="AppTheme" parent="Theme.AppCompat.DayNight.DarkActionBar"> // or the themw you are using
...
...
<item name="android:seekBarStyle">@style/MySeekBarStyle</item>
</style>
//或您正在使用的themw
...
...
@style/MySeekBarStyle
还添加了一个新样式
<style name="MySeekBarStyle" parent="android:Widget.SeekBar">
<item name="android:colorControlNormal">@color/gray</item> // put here the color for disable state
</style>
@颜色/灰色//将禁用状态的颜色放在此处
controlColorNormal
用于禁用状态,而colorAccent
用于启用状态您可以使用选择器作为Seekbar的背景
选择器设置满足条件时所需的内容(此处:android:state\u enabled=“true”
)
在“活动/片段”布局中,您将seekbar放置在一个作为选择器的背景中:
<SeekBar
android:id="@+id/seekbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/selector_seekbar"/>
在可绘制文件夹中创建选择器:
选择器_seekbar.xml
如果启用,seekbar将为全绿色,否则将为灰色
你可以做同样的事情,如果seekbar是集中,按下等方式
您不仅可以设置颜色,还可以设置整个可绘制的颜色。您可以使用选择器作为Seekbar的背景 选择器设置满足条件时所需的内容(此处:
android:state\u enabled=“true”
)
在“活动/片段”布局中,您将seekbar放置在一个作为选择器的背景中:
<SeekBar
android:id="@+id/seekbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/selector_seekbar"/>
在可绘制文件夹中创建选择器:
选择器_seekbar.xml
如果启用,seekbar将为全绿色,否则将为灰色
你可以做同样的事情,如果seekbar是集中,按下等方式
您不仅可以设置颜色,还可以设置整个绘图