2013年3月11日
来源:互联网 发布:eregi() 网页源码 编辑:程序博客网 时间:2024/05/16 09:14
1、TextView里的setText方法支持一下多态构造方法:
public final void setText (CharSequence text) public final void setText (int resid) public void setText (CharSequence text, TextView.BufferType type) public final void setText (int resid, TextView.BufferType type) public final void setText (char[] text, int start, int len)
在此,以最后public final void setText (char[] text, int start, int len)为例,第一个参数为char数组作为输出数据,第二个参数为从哪一个元素索引开始选取,第三个参数则为要取出多少个元素,例如:
Char[] char = {D , a , v , i , d};
textView01.setText(char , 1 , 3);
上述程序输出的结果是”avi”,懂了吧?但是要注意TextView.setText()不支持HTML TAG的输出,所以即便写成这样:
textView.setText(“<a href=\”http://blog.csdn.net/zhai56565\”>小武的博客</a>”);
实际输出时也就是纯文本而已,不会作HTML TAG转换。但是在TextView里加上Android:autoLink=”all”,那么正文中有网址(http://),则可以显示出来,例如:
<TextView android:id="@+id/textView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:autoLink="all" android:text="请访问我的博客:http://blog.csdn.net/zhai56565" />
2、drawable定义颜色常数的方法
事先将定义好的颜色代码(color code)以drawable的名称(name)存放于resource当中,这是学习开发Android程序必须养成的好的习惯,正如存储字符串常数一样,使用如下两种方式:
<drawable name = “black”>#000000 </drawable>
<color name="white">#ffffff</color>
定义好的drawable name常数必须存放在res/values下面作为资源使用,但定义好的颜色并非只能在XML中使用,也可以通过程序来更改:
Resources resources = getResources(); Drawable drawable = resources.getDrawable(R.drawable.black); textView01.setBackgroundDrawable(drawable); int color = resources.getColor(R.color.white); textView01.setBackgroundColor(color);
下面是色值表大全http://blog.csdn.net/zhai56565/article/details/8087924
3、取得手机屏幕的大小:
Display display = getWindowManager().getDefaultDisplay();
int Width = display.getWidth();
int height = display.getHeight();
4、使用Style样式简化程序代码
下面在res/values/styles.xml中定义textView的样式:
<resources xmlns:android="http://schemas.android.com/apk/res/android"> <style name="TextView_Top"> <item name="android:textSize">18dp</item> <item name="android:textColor">@color/white</item> </style> <style name="TextView_Bottom"> <item name="android:textSize">130dp</item> <item name="android:textColor">@drawable/black</item> <item name="android:textStyle">bold</item> <item name="android:shadowColor">@color/white</item> <item name="android:shadowDx">4dp</item> <item name="android:shadowDy">4dp</item> <item name="android:shadowRadius">2dp</item> </style></resources>
下面将样式绑定在TextView上:
<TextView android:id="@+id/textView01" android:layout_width="wrap_content" android:layout_height="wrap_content" style="@style/TextView_Top" android:autoLink="all" android:text="请访问我的博客:http://blog.csdn.net/zhai56565" />
- 2013年3月11日
- 3月11日
- 11月3日
- 2013年3月11日 自定义按钮效果
- [日记]2013年11月11日
- 2013年8月11日
- 2013年9月11日热身赛
- 2013年08月11日日志
- 2013年11月1日
- 2013年11月6日
- 2013年11月18日
- 2013年11月23日
- 2013年11月21日
- 2013年08月11日
- 2013年11月29日
- 2013年11月30日
- 2013年3月6日
- 2013年3月1日
- JSP简介
- [流媒体]Android 实时视频采集/编码/传输/解码/播放—方案调研(初)
- eclipse提取公共代码到私有的公共方法
- FlashPlayer 后缀的各种意思SA AX
- 利用rsync同步文件
- 2013年3月11日
- CheckIO题解:OLD LIBRAY 里的部分题目
- Android--Android 开发程序的优化
- GPS通讯协议(NMEA0183)协议解析
- 国际市场产品分析手段--Hidden Market Research on Ebay, Amazon, and Others
- [流媒体]Android 实时视频编码—H.264硬编码
- js无缝图片滚动
- eclipse常见问题及解决
- c#设置或者获取byte(字节、8位二进制整数)某位的的值的代码