网上找了很多,还是没有直接的解决办法,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>

更多相关文章

  1. 其实你不懂:Android之TextView 不常用的几个方法
  2. android(3)
  3. android 正确获取屏幕像素大小
  4. Android(安卓)keystore的使用方法
  5. Dialog与DialogFragment
  6. Android获取控件高度如何才能不为0
  7. android 10 手机无法预览到图片, 加载图片, 无法显示图片内容问
  8. android源码单独编译的方法
  9. Android(安卓)全屏或者取消标题栏

随机推荐

  1. Android--Task(stack)的使用
  2. Android(安卓)2018最新验证手机号正则表
  3. ReactNative对接Android步骤
  4. 实现仿windows正在加载loading动画
  5. android studio仿真时遇到VT-x is disabl
  6. android+面试题
  7. 我家云/粒子云Rockchip RK3328将Android
  8. Android(安卓)Intent传递对象的两种方法(
  9. Android之TextView实现文字过长时省略部
  10. android 读取文件相关