首页 > 移动平台 > 详细

android 怎么动态设置button 的style

时间:2015-05-26 20:56:19      阅读:513      评论:0      收藏:0      [点我收藏+]

网上找了很多,还是没有直接的解决办法,button没有setstyle这个方法。因此我的解决办法如下:

直接动态设置各个属性

Button themeBtn = new Button(this);
            themeBtn.setText(entry.getKey());
            LayoutParams lparams = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.MATCH_PARENT);
            themeBtn.setLayoutParams(lparams);
            themeBtn.setTextAppearance(this, R.style.ImageCategoryThemeBtn);
            themeBtn.setPadding(DensityUtils.dp2px(this, 8), 0, DensityUtils.dp2px(this, 8), 0);
            themeBtn.setBackgroundResource(R.drawable.selector_bt_gray2blue);
            v_theme.addView(themeBtn);

 

style:

<style name="ImageCategoryThemeBtn" parent="@android:style/Widget.Button">
        <item name="android:textColor">@color/image_theme</item>
        <item name="android:textSize">@dimen/imageThemeBtnTextSize</item>
    </style>

 

android 怎么动态设置button 的style

原文:http://www.cnblogs.com/feijian/p/4531333.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!