码迷,mamicode.com
首页 > 移动开发 > 详细

android 怎么动态设置button 的style

时间:2015-05-26 20:58:40      阅读:415      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!