我试图以编程方式更改按钮的背景色,但是当我更改其颜色按钮时从屏幕消失。设置按钮背景编程从屏幕上将其删除
这里是布局
<Button
android:id="@+id/ibtn_EA_ColorPick_new"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@drawable/clr_btn"
/>
按钮,这里是我如何改变其背景
btn_ColorPick.setBackgroundColor(btn_ColorPick.getContext().getResources().getColor(R.color.BlackColor));
我也曾尝试
btn_ColorPick.setBackgroundColor(getResources().getColor(R.color.BlackColor));
但同样的结果
你有没有尝试删除'机器人:背景= “@绘制/ clr_btn”''从一个xml' d改为添加一个'bacgroundColor =“@ android:colors/red”',然后尝试如果相同的行为 – hrskrs
是您的活动背景并且按钮颜色相同? –