老司机代码

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/sw399622565/article/details/52127454

一、ScrollView中的TextView添加滚动条监听事件(解决滑动监听冲突)

  textView = (TextView) findViewById(R.id.info_desc);
  textView.setMovementMethod(ScrollingMovementMethod.getInstance());
  textView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                // TODO Auto-generated method stub
                if(event.getAction()==MotionEvent.ACTION_DOWN){
                    //通知父控件不要干扰
                    v.getParent().requestDisallowInterceptTouchEvent(true);
                }
                if(event.getAction()==MotionEvent.ACTION_MOVE){
                    //通知父控件不要干扰
                    v.getParent().requestDisallowInterceptTouchEvent(true);
                }
                if(event.getAction()==MotionEvent.ACTION_UP){
                    v.getParent().requestDisallowInterceptTouchEvent(false);
                }
                return false;
            }
        });

二、ViewPager+banner轮播
http://www.jianshu.com/p/2e577242fe87

三、沉浸式状态栏(状态栏最上面和app颜色一致)

SystemBarTintManager

android:fitsSystemWindows="true"
android:clipToPadding="true"

//Android4.4 沉浸模式使通知栏和app最上端颜色一致

//透明状态栏
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
//透明导航栏
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
    setTranslucentStatus(true);
    SystemBarTintManager mTintManager = new SystemBarTintManager(this);
    mTintManager.setStatusBarTintEnabled(true);
    mTintManager.setNavigationBarTintEnabled(true);
    mTintManager.setTintColor(Color.parseColor("#54AC34"));
}

//沉浸式状态栏

private void setTranslucentStatus(boolean on) {
        Window win = getWindow();
        WindowManager.LayoutParams winParams = win.getAttributes();
        final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
        if (on) {
            winParams.flags |= bits;
        } else {
            winParams.flags &= ~bits;
        }
        win.setAttributes(winParams);
    }

//获取导航栏高度

       Class<?> c = null;
        Object obj = null;
        Field field = null;
        int x = 0, sbar = 0;
        try {
            c = Class.forName("com.android.internal.R$dimen");
            obj = c.newInstance();
            field = c.getField("status_bar_height");
            x = Integer.parseInt(field.get(obj).toString());
            sbar = getResources().getDimensionPixelSize(x);
            Log.v("TAG", sbar + "");
        } catch(Exception e1) {
            e1.printStackTrace();
        }

软键盘 覆盖屏

android:windowSoftInputMode="stateUnspecified|adjustPan"

向上压缩屏幕内容

android:windowSoftInputMode="adjustResize" 

动态设置hint大小,与textsize不一致

EditText editText = (EditText) rootView.findViewById(R.id.et);
// 新建一个可以添加属性的文本对象
SpannableString ss = new SpannableString("喝酒就要喝一斤!");
// 新建一个属性对象,设置文字的大小
AbsoluteSizeSpan ass = new AbsoluteSizeSpan(8,true);
// 附加属性到文本
ss.setSpan(ass, 0, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
// 设置hint
editText.setHint(new SpannedString(ss)); // 一定要进行转换,否则属性会消失

空格

&#160;

倒计时60秒的button

 public static int count = 60;
    private Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            button_sendcode.setText("已发送("+msg.what+"秒)");
            if(msg.what==0){
                button_sendcode.setEnabled(true);
                button_sendcode.setText("获取验证码");
            }
        }
    };

 public void startCount() {
        count=60;
        button_sendcode.setEnabled(false);
        timer = new Timer();
        timerTask = new TimerTask() {
            @Override
            public void run() {
                if (count >= 0) {
                    handler.sendEmptyMessage(count);
                }
                else
                {
                    timerTask.cancel();
                }
                count --;
            }
        };
        timer.schedule(timerTask,0, 1000);
    }

//弹出alertDialog

 //签收弹框
    AlertDialog builder;
    private void ifSing(final int index){
        builder = new AlertDialog.Builder(MyOrderListQuick.this).
                setMessage("是否确认签收").
                setPositiveButton("确认", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        //是否签收
                        Sing(index);
                        dialog.dismiss();
                    }
                }).
                setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                }).create();
        builder.show();
        builder.setCanceledOnTouchOutside(false);
    }

//密码格式

<android:digits="qwertyuioplkjhgfdsazxcvbnmQWERTYUIOPLKJHGFDSAZXCVBNM1234567890_">

//查看任务栈信息

Terminal中输入:adb shell dumpsys activity activities

//只看activity

adb shell dumpsys activity activities | sed -En -e '/Running activities/,/Run #0/p'

//横竖屏切换不加载oncreate等方法

 android:configChanges="orientation|keyboardHidden|screenSize"

//Android studio ADB启动失败
1.打开cmd,输入adb kill-server,adb start-server,adb nodaemon server
启动不起来是因为adb的端口被占用了
2.输入netstat -aon|findstr “5037”,可以看到进程号为10624的进程(这个进程号因机器和时间而异)在占用5037端口(adb需要使用此端口)
3.打开任务管理器,选择“进程”选项卡,点击选项栏“查看-选择列…”,勾选“PID(进程标识符)”,点确定。会看到每个进程都会显示它们的PID了。找到进程号为10624的进程,结束这个进程。
4.在cmd中,重新adb start-server,会看到成功启动了。
5.重启Android Studio,正常启动完成。

Android studio 配置Android annotation(注解)
http://blog.csdn.net/hanhailong726188/article/details/40585057

小米monkey测试 参数

C:\Users\Administrator>adb shell monkey -v --throttle 300 --pct-touch 30 --pct-motion 20 --pct-nav 20 --pct-majornav 15 --pct-appswitch 5 --pct-anyevent 5 --pct-trackball 0 --pct-syskeys 0 -p com.enlife.store 10000
展开阅读全文

没有更多推荐了,返回首页