advanced-textview展示

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&#160;line
  </string>

6 GradientTextActivity

    Shad
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值