更改Android的微调文本颜色按钮时pressed [英] Change Android spinner text color when button pressed
问题描述
我有一系列的重新present一系列主题的ToggleButtons。当切换,切换按钮改变其背景颜色来表示其状态。当在检查
状态下,切换按钮有一个较深的颜色。
I have a series of ToggleButtons which represent a series of topics. When toggled, the ToggleButton changes its background color to indicate its state. When in the checked
state, the ToggleButton has a darker color.
一个微调覆盖切换按钮,允许用户选择该主题的难度。
A Spinner overlays the ToggleButton and allows the user to select a difficulty for the topic.
如何更改微调的文本颜色(白色)切换按钮是pressed什么时候?我想我可以处理不断变化的微调选择,但我在努力制定出一个方法来改变文字颜色。
How do I change the text color (to white) of the Spinner when the ToggleButton is pressed? I think I can handle changing the spinner selector, but I'm struggling to work out a way to change the text color.
推荐答案
请尝试以下方法。
- 创建一个名为XML
spinnertext.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/spinnerText"
style="?android:attr/spinnerItemStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingBottom="2dp"
android:paddingLeft="6dp"
android:textColor="#41f2f3" />
现在在code。
ArrayAdapter<String> sp_adapter = new ArrayAdapter<String>(this, R.layout.spinnertext, your_array);
sp.setAdapter(sp_adapter);
然后切换按钮的工作
Then work with toggle button
ToggleButton tb = (ToggleButton) findViewById(R.id.toggleButton1);
tb.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton arg0, boolean isChecked) {
TextView tv = (TextView) findViewById(R.id.spinnerText);
if (isChecked)
tv.setTextColor(Color.RED);
else
tv.setTextColor(Color.BLUE);
}
});
参考。
试试这个方法。这对我的作品。我希望这将工作你了。
Try this way. This works for me. I hope this will work you too.
这篇关于更改Android的微调文本颜色按钮时pressed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!