android 怎么动态设置button 的style
16lz
2021-01-25
网上找了很多,还是没有直接的解决办法,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之TextView 不常用的几个方法
- android(3)
- android 正确获取屏幕像素大小
- Android(安卓)keystore的使用方法
- Dialog与DialogFragment
- Android获取控件高度如何才能不为0
- android 10 手机无法预览到图片, 加载图片, 无法显示图片内容问
- android源码单独编译的方法
- Android(安卓)全屏或者取消标题栏