1)设置文本是否包含顶部和底部的额外空白
在xml文件的TextView控件中加入如下属性:

        android:includeFontPadding="false" 

2)有时直接引用资源文件不起作用(例如:textView.setTextColor(R.color.red)),可做如下处理:

        textView.setTextColor(context.getResources().getColor(R.color.red));

3)textview中可以显示多行,但是行数是有限制的,比如最多两行,如果第二行依然显示不下,显示singleline的效果

        android:maxLines="2" 


4)文字的雕刻效果

        <TextView            android:layout_width="fill_parent"            android:layout_height="wrap_content"            android:background="@drawable/title_bg"            android:gravity="center_vertical|center_horizontal"            android:shadowColor="#000000"            android:shadowDx="0"            android:shadowDy="-2"            android:shadowRadius="0.1"            android:text="雕刻效果的文字"            android:textColor="#ffffff"            android:textSize="28px" />


5)跑马灯效果

<!--layout_width属性要小于文字的宽度,android:singleLine="true"以及android:focusable="true"属性也必须的。当TextView获得焦点时,会出现跑马灯效果。--><TextView android:layout_width="50px" android:layout_height="wrap_content"android:singleLine="true" android:focusable="true" android:text="跑马灯效果 "android:ellipsize="marquee" android:marqueeRepeatLimit="marquee_forever" />


6)中文字体加粗效果

((TextView) findViewById(R.id.test)).getPaint().setFakeBoldText(true);


7)点击时TextView中文字颜色变化

首先建立res\color文件夹,然后创建textview_colors_selector.xml文件,内容如下:

<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android">    <item android:state_selected="true" android:color="#3399FF"/>    <item android:state_focused="true" android:color="#3399FF"/>    <item android:state_pressed="true" android:color="#3399FF"/>    <item android:color="#FFFFFF"></item></selector>


然后在main.xml文件中指定TextView的textColor属性:

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:orientation="vertical" >    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_gravity="center"        android:clickable="true"        android:text="点击我会变颜色的哦!"        android:textColor="@color/textview_colors_selector"        android:textSize="24sp" /></LinearLayout>


正常状态:

点击状态:

更多相关文章

  1. android Animator详解
  2. activity属性设置大全
  3. Android(安卓)图片加水印
  4. Android中自定义属性(attrs.xml,TypedArray的使用)
  5. LinearLayout && RelativeLayout 常用属性
  6. 关于android:configChanges的属性
  7. android圆角、边框、画线效果、RatingBar背景
  8. android 中的 edittext属性大全
  9. Android学习笔记:androidmanifest.xml 高级属性

随机推荐

  1. ADT下载地址(含各版本)(转)
  2. [Android]Android(安卓)Studio设置debug
  3. Android与JS互调
  4. Android(安卓)TextView 设置超链,设置部分
  5. android中自定义shape
  6. Android布局的一些属性值
  7. Android在listview添加checkbox实现
  8. Android之各种事件触发方案
  9. 2010.10.26———Android(安卓)01
  10. android 3G pppd 调试记录