1 MainActivity
android:textIsSelectable=”true”的意思为文本是否可以复制,如果是true可以复制如果是false不可以复制
TextView footer = (TextView) LayoutInflater.from(this).inflate(
android.R.layout.simple_list_item_1, getListView(), false);
listview.addFooterView(footer);
SimpleAdapter adapter = new SimpleAdapter(
this,
demos,//是一个集合
android.R.layout.simple_list_item_2,
new String[]{Demo.KEY_TITLE, Demo.KEY_SUBTITLE},
new int[]{android.R.id.text1, android.R.id.text2});
public static class Demo extends HashMap<String, String> {
//自定义包含类名的Map
public static final String KEY_TITLE = "title";
public static final String KEY_SUBTITLE = "subtitle";
public final Class<?> activityClass;
public Demo(Context context, Class<?> activityClass, int titleId, int subtitleId) {
this.activityClass = activityClass;
put(KEY_TITLE, context.getString(titleId));
put(KEY_SUBTITLE, context.getString(subtitleId));
}
}
2 AnimatedCompoundDrawableActivity
左边一直旋转,右边是图片不断切换模拟wifi信号变化
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:drawableLeft="@drawable/rotating_loading"
android:drawableRight="@drawable/animated_wifi"
android:drawablePadding="8dp"/>
<animated-rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:pivotX="50%"
android:pivotY="50%"
android:drawable="@drawable/ic_loading"
android:duration="500" />
<animation-list
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ic_wifi_0" android:duration="250" />
<item android:drawable="@drawable/ic_wifi_1" android:duration="250" />
<item android:drawable="@drawable/ic_wifi_2" android:duration="250" />
<item android:drawable="@drawable/ic_wifi_3" android:duration="250" />
</animation-list>
// 在onStart和onStop中分别调用开启和关闭
private void changeAnimation(Operation operation) {
Drawable[] drawables = textView.getCompoundDrawables();
for (Drawable drawable : drawables) {
if (drawable != null && drawable instanceof Animatable) {
Animatable animatable = ((Animatable) drawable);
switch (operation) {
case START:
animatable.start();
break;
case STOP:
animatable.stop();
break;
}
}
}
}
3 ShadowTextActivity
依次对应的配置
<TextView
android:textColor="@color/purple"
android:textSize="@dimen/text_size_huge"
android:padding="12dp"
android:shadowColor="@color/green"
android:shadowDx="4"
android:shadowDy="-4"
android:shadowRadius="5"
android:textStyle="bold"/>
-- android:shadowDx="4"
android:shadowDy="-4"
android:shadowRadius="1"
-- android:shadowDx="0"
android:shadowDy="0"
android:shadowRadius="24"
说明:android:shadowColor :阴影颜色,android:shadowDx :阴影x方向位移
android:shadowDy :阴影y方向位移,android:shadowRadius :阴影的半径。
注意:阴影的半径必须设,为0时没有效果
4 CustomFontActivity
Ruthie.ttf为assets文件夹中的一个文件
public class CustomFontActivity extends Activity {
private Typeface typeface;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
typeface = Typeface.createFromAsset(getAssets(), "Ruthie.ttf");
setContentView(R.layout.activity_custom_font);
}
@Override
public View onCreateView(View parent, String name, Context context, AttributeSet attrs) {
//this would apply to all textviews in the app
if (name.equals("TextView")) {
TextView view = new TextView(this, attrs);
view.setTypeface(typeface);
return view;
}
return super.onCreateView(parent, name, context, attrs);
}
@Override
public View onCreateView(String name, Context context, AttributeSet attrs) {
//this would apply to all textviews in the app
if (name.equals("TextView")) {
TextView view = new TextView(this, attrs);
view.setTypeface(typeface);
return view;
}
return super.onCreateView(name, context, attrs);
}
}
5 NonBreakingSpaceActivity
<string name="non_breaking_space_text">A sentence that takes more than one line</string>
<string name="non_breaking_space_text_nbsp">
A sentence that takes more than one line
</string>
6 GradientTextActivity
Shad