2017-09-11 21 views
0

更改主题,从按钮我有一个qutestion(pfff)我如何能在Android的

我有一个自定义主题启用和禁用状态的按钮。

 <Button 
      android:id="@+id/btn_on_off" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="activar" 
      android:textColor="#ffffff" 
      android:textStyle="bold" 
      android:theme="@style/**MY_STYLE_A**" /> 

我想通过来源更改主题。 例如更改文本:myButton.setText("new text");

  <Button 
      android:id="@+id/btn_on_off" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="activar" 
      android:textColor="#ffffff" 
      android:textStyle="bold" 
      android:theme="@style/**MY_STYLE_B**" /> 

我想,但我没有成功

+0

你想改变风格或按钮颜色? –

回答

0

你想以编程方式更改按钮样式?

这里试试这一个

btn.setTextAppearance(背景下,R.style.MY_STYLE_B);

+0

喜是的,我想,但到的“变革”安卓主题“” 自定义样式有两种颜色设计点击例如: 启用风格=绿色和白色 禁用风格=红色和白色 和setTextAppearance不工作我的 –

+0

也许你可以为你的按钮创建一个自定义样式的XML文件,并将其设置为android:background =“@ drawable/custom_style”。该设置在你的代码中改变它,像这样button.setBackgroundResource(R.drawable.custom_style); –