Android常见问题剖析

时间:2022-06-17
本文章向大家介绍Android常见问题剖析,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

一、 Edittext编辑完成后让键盘的“完成”变成“搜索”样式

1.先设置属性Android:singleline =“true”

2.再设置Android:imeOptions=“actionSearch”

二、 ArrayList去除重复数据

private ArrayList singleElement(ArrayList dateCount) {
        ArrayList newAl = new ArrayList();

        for(Iterator it = dateCount.iterator(); it.hasNext();)
        {
            Object obj = it.next();
            if(!newAl.contains(obj))
            {
                newAl.add(obj);
            }
        }
        return newAl;
    }

三、给shape设置背景颜色

GradientDrawable background=(GradientDrawable)iv_test_background_changge.getBackground();
background.setColor(getResources().getColor(R.color.colorPrimaryDark));

四、Adb 截图

 第一步:现将图片截图下来
 adb shell screencap -p /sdcard/screen.png   
 第二步:再将图片复制到电脑上
 adb pull /sdcard/screen.png 

五、安卓执行DOS命令

Runtime.getRuntime().exec("inputkeyevent20");
执行exec中的String命令

六、获得 LayoutInflater 实例的三种方式:

//调用Activity的getLayoutInflater()
1.LayoutInflater inflater = getLayoutInflater(); 

2.LayoutInflater localinflater =(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

3. LayoutInflater inflater = LayoutInflater.from(context);