# Android 开发实用小工具


Case 1

// 格式化小数点后位数
String tmp = String.format("tmp: ¥%.2f", 1f);
System.out.println(tmp); ==> tmp: ¥1.00

// 也可以这么用
DecimalFormat df = new DecimalFormat("0.00");
String tmp = df.format(1f);
System.out.println(tmp); ==> 1.00

Case 2

// 数字前位补0
String tmp = String.format("tmp: %04d", 2);
System.out.println(tmp); ==> tmp: 0002

// 也可以这么用
DecimalFormat df = new DecimalFormat("0000");
String tmp = df.format(2);
System.out.println(tmp); ==> 0002

Case 3

// 判断字符串是否为null或空字符
TextUtils.isEmpty(null) ==> true
TextUtils.isEmpty("") ==> true
// 判断字符串是否是纯数字
TextUtils.isDigitsOnly("1234") ==> true
TextUtils.isDigitsOnly("a123") ==> false

Case 4

View.java 
/**   
 * 可以获取View在Screen上的坐标位置
 * Computes the coordinates of this view on the screen. The argument
 * must be an array of two integers. After the method returns, the array
 * contains the x and y location in that order.
 *
 * @param location an array of two integers in which to hold the coordinates
 */
public void getLocationOnScreen(int[] location)

/**
 * 可以获取View在其所在Window内的坐标位置
 * Computes the coordinates of this view in its window. The argument
 * must be an array of two integers. After the method returns, the array
 * contains the x and y location in that order.
 *
 * @param location an array of two integers in which to hold the coordinates
 */
public void getLocationInWindow(int[] location)

Case 5

/** 
 * 如果应用内有需要自己实现Activity的堆栈管理
 * 不需要在每个Activity的生命周期内挨个方法添加事件了
 * registerActivityLifecycleCallbacks已经帮您实现好啦。
 */
public class TestApplication extends Application {
    public void onCreate() {    
      super.onCreate();    
      this.registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {    

        @Override    
        public void onActivityStopped(Activity activity) {    
            // activity onStop    
        }    

        @Override    
        public void onActivityStarted(Activity activity) {    
            // activity onStart
        }    

        @Override    
        public void onActivitySaveInstanceState(Activity activity, Bundle outState) {    
            // activity onSaveInstanceState
        }    

        @Override    
        public void onActivityResumed(Activity activity) {    
            // activity onResume    
        }    

        @Override    
        public void onActivityPaused(Activity activity) {    
            // activity onPause    
        }    

        @Override    
        public void onActivityDestroyed(Activity activity) {    
            // activity onDestroy    
        }    

        @Override    
        public void onActivityCreated(Activity activity, Bundle savedInstanceState) {    
            // activity onCreate
        }    
      });    
    }
}

Case 6

<Space/>

Case 7

<ViewStub/>

Case 8

<Merge>

Case 9

**android:animateLayoutChanges=”true”**LinearLayout中添加View的动画的办法,支持通过setLayoutTransition()自定义动画

Case 10

GradientDrawable渐变,可实现阴影效果

<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape=["rectangle", "ring", "oval", "line"]>

   <corners
        android:radius="5dp"
        android:bottomLeftRadius="5dp"
        android:topLeftRadius="5dp"
        android:bottomRightRadius="5dp"
        android:topRightRadius="5dp"/>

    <stroke android:color="#00ffff"
        android:dashGap="3dp"
        android:dashWidth="10dp"
        android:width="1dp"/>

    <solid android:color="#ff00"/>
</shape>

Case 11

Android 开发你想要的工具,这里基本都全了。

http://www.apkbus.com/thread-252748-1-1.html
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值