在Android中,可以通过以下方法设置按钮的背景颜色:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:background="@color/colorAccent" />
其中,@color/colorAccent
是指向颜色资源文件中定义的颜色。
Button button = findViewById(R.id.button);
button.setBackgroundColor(ContextCompat.getColor(this, R.color.colorAccent));
其中,R.color.colorAccent
是指向颜色资源文件中定义的颜色。
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: android悬浮窗贴边的方法是什么