android 按钮背景描边,Android如何以编程方式设置按钮描边和半径

我有48 Button这个活动,用户可以触摸并更改文本和背景颜色。Android如何以编程方式设置按钮描边和半径

我已经编辑默认Buttons的风格像这样 742292f7309384a2d4a2a9cb532a7a6a.png

但是,当用户改变背景颜色,我有这种坏的结果

4fa3817a06f9a13f2f5b6284827cd332.png

这些都是xmls风格的默认Buttons

buttons.xml

android:state_pressed="true" />

android:state_focused="true" />

button_default.xml

android:radius="100dp"

/>

android:color="#FFFFFF"

/>

android:left="0dp"

android:top="0dp"

android:right="0dp"

android:bottom="0dp"

/>

android:width="3dp"

android:color="#787878"

/>

在其它XML只更改颜色,所以我尽量避免将其发布。 这里是以编程方式更改Button的代码。 我拿起DB全部变更Button用ID保存并设置为Button的颜色。

//Get all materie inside database

List materia = db.getAllMaterie();

//change all TextView inputed from user

if(materia.isEmpty()){

//do nothing

}else {

for (Materia mat : materia) {

//Change all the Button with values stored inside the database

int resId = getResources().getIdentifier(mat.getID(), "id", getPackageName());

final Button changedButton = (Button) findViewById(resId);

changedButton.setText(mat.getMateria());

changedButton.setTypeface(null, Typeface.BOLD);

changedButton.setBackgroundColor(mat.getColor());

}

}

但我失去的半径和笔触属性。 有一些方法可以通过编程来设置它们吗? 接受其他建议!

2016-01-03

Dario

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值