动态添加的Button不显示字体
来源:互联网 发布:扁鹊化身博士淘宝有吗 编辑:程序博客网 时间:2024/03/29 20:43
动态添加了一个小按钮,但是按钮上的字体却没显示出来,代码如下
LinearLayout layout; super.onCreate(savedInstanceState); setContentView(R.layout.main); layout = (LinearLayout)findViewById(R.id.myLayout); LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(20,20); Button bt = new Button(this); bt.setBackgroundColor(0xffffffff); bt.setText("L"); bt.setTextSize(TypedValue.COMPLEX_UNIT_PX,15); bt.setTextColor(0xff000000); layout.addView(bt, param);
一模一样的按钮,如果是在布局文件中添加的,则可以显示字体
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/myLayout" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <Button android:layout_width="20px" android:layout_height="20px" android:background="#ffffffff" android:textSize="15px" android:textColor="#ff000000" android:text="L" /></LinearLayout>
后来发现好像动态添加的按钮会有默认的padding,所以当Button大小比较小的时候,就把字体给挤掉了,那么加上padding设置为0就可以解决了:
LinearLayout layout; super.onCreate(savedInstanceState); setContentView(R.layout.main); layout = (LinearLayout)findViewById(R.id.myLayout); LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(20,20); Button bt = new Button(this); bt.setBackgroundColor(0xffffffff); bt.setText("L"); bt.setTextSize(TypedValue.COMPLEX_UNIT_PX,15); bt.setTextColor(0xff000000); bt.setPadding(0,0,0,0); layout.addView(bt, param);
- 动态添加的Button不显示字体
- 动态设置Button的透明度文字不显示问题
- MFC中【Button】控件上局部动态显示字体信息和【对话框】名字的动态字体赋值性变化
- Button显示不同字体
- 获取滑动条位置,动态调整对话框显示位置;为动态添加的button添加click事件
- gridbaglayout不显示是因为panel没有添加具体的button/label
- 关于在navigationItem.titleView上添加button不显示问题
- 动态添加带图标的Button
- 【实验】button的使用、动态添加组件
- 动态创建的CButton按钮,在设置字体时为什么不显示
- C# 动态添加Button
- 动态添加button按钮
- Android--在一个Button上显示不同类型的字体
- UIScrollviewview上添加button不显示和button滑动超出范围问题
- java不添加本地字体的情况下使用字体
- cclabelttf字体不显示的解决办法
- 字体图标显示不出来的解决办法
- Unity在NGUI中默认动态字体Arial字体显示不完整解决方案
- 这几天写java遇到的问题
- JavaBean编写规则
- 为什么要有cookie和session,以及cookie和session的区别
- 程序员的十层楼
- JCombBox实现检索功能
- 动态添加的Button不显示字体
- hdu4362 Dragon Ball(dp+单调队列优化)
- NSString
- Logo设计中的黄金分割率
- 【团队旅游】2012 7 月 中国珍珠宝石城荣耀之旅
- v$type 简单记录
- 移动端HTML5只是浏览器厂商的臆造神话?
- [转载]姚期智:科学家与科学之路
- tomcat+apache入门做集群