小问题集合

1.在java中获取String中的内容

String str=getResources().getString(R.string.hello_world);

 2.获取屏幕密度值

float xdpi = getResources().getDisplayMetrics().xdpi;
float ydpi = getResources().getDisplayMetrics().ydpi;

 3.设置透明背景

  <color name="empty">#00000000</color>

 4.安装过程出现安装失败,可能原因是已经存在此app,需要重新安装

他是骗你的,问题在于修改了包名(首字母不能大写,允许有下划线,其他字母可以大写),或者MainFest文件丢失

5.转成字符串

String.valueof(123);

 6.notificatio


            NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
                //创建notificationManager实例manager
            NotificationCompat.Builder mBuilder =
                    new NotificationCompat.Builder(context)//创建自己的通知mBuilder
                            .setSmallIcon(R.mipmap.icon)
                            .setContentTitle("My notification")
                            .setContentText("Hello World!");
            Notification notification = mBuilder.build();//生成
        
      //FLAG_AUTO_CANCEL   该通知能被状态栏的清除按钮给清除掉
      //FLAG_NO_CLEAR 该通知不能被状态栏的清除按钮给清除掉
      //FLAG_ONGOING_EVENT 通知放置在正在运行
      //FLAG_INSISTENT 是否一直进行,比如音乐一直播放,知道用户响应
      notification.flags |= Notification.FLAG_ONGOING_EVENT; // 将此通知放到通知栏的"Ongoing"即"正在运行"组中
      notification.flags |= Notification.FLAG_NO_CLEAR; // 表明在点击了通知栏中的"清除通知"后,此通知不清除,经常与FLAG_ONGOING_EVENT一起使用
           manager.notify(1,notification);//显示

 7.获取系统时间

Calendar c = Calendar.getInstance();

hour = c.get(Calendar.HOUR_OF_DAY);
minute = c.get(Calendar.MINUTE)

 8.切换到后台

 moveTaskToBack(true);

 9.字符串对比

str2.equals(str3)

10.EditText焦点监控

EditText searchView = (EditText) findViewById(R.id.search_text);
searchView.setOnFocusChangeListener(new android.view.View.
        OnFocusChangeListener() {
    @Override
    public void onFocusChange(View v, boolean hasFocus) {
        if (hasFocus) {
            // 此处为得到焦点时的处理内容
        } else {
            // 此处为失去焦点时的处理内容
        }
    }
});

 11.shape画图示范

   http://blog.163.com/sunshengleissl@126/blog/static/108698504201462910714837/

12.获取屏幕宽度

// 获取屏幕宽高(方法1)  
int screenWidth = getWindowManager().getDefaultDisplay().getWidth(); // 屏幕宽(像素,如:480px)  
int screenHeight = getWindowManager().getDefaultDisplay().getHeight(); // 屏幕高(像素,如:800p)

 13.获取当前文件所在路径

System.out.println(System.getProperty("user.dir"));

 14.动态加载View

(1)FindViewByid找到对应的Layout

LinearLayout FileSaveLinearLayout = (LinearLayout) findViewById(R.id.FileSaveLinearLayout);

(2)Layout对象addView()

TextView Line1 = new TextView(FileSaveActivity.this);
TextView Line2 = new TextView(FileSaveActivity.this);
TextView Line3 = new TextView(FileSaveActivity.this);
FileSaveLinearLayout.addView(Line1);
FileSaveLinearLayout.addView(Line2);
FileSaveLinearLayout.addView(Line3);

15.同时实现多个按键监控

    FileSaveButton.setOnClickListener(mListener);
    FileGetButton.setOnClickListener(mListener);

    private View.OnClickListener mListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.FileSaveButton:
                        //todo
                    break;
                case R.id.FileGetButton:
                        //todo
                        break;
                    }
            }
        }
    };

16.多个设备error: more than one device/emulator

原 因:存在多个设备或模拟设备
解决办法:列出所有设备
>adb devices
>adb -s 选择所需设备

17.启动别的程序

关于调用非mainActivity方法,参考隐式Intent

Intent intent1 = new Intent();
//通过包名和activity名启动应用
intent1.setComponent(new ComponentName("com.cenzhongman.myapplication2","com.cenzhongman.myapplication2.MainActivity"));
startActivity(intent1);

18.EditText默认不自动获取焦点

  • 在xml中在EditText父节点增加
android:focusable="true" 
android:focusableInTouchMode="true" -------表示将焦点给EditText的父节点
  • 在代码中清除EditText的焦点
EditText editText= (EditText)findViewById(R.id.editText);
editText.clearFocus();
editText.setSelected(false);

19.Layout被覆盖问题

   砌墙的砖头——后来居上

20.为什么包名要用公司域名倒着写

 包名倒置遵循了“DNS翻转”约定,因为域名绝对是唯一的,可以很好地避免了包名重复问题,还具有很高的识别度

21.数组循环的算法

    //0~1~2~3~0~1~2~3......
    mCurrentIndex = (mCurrentIndex + 1) % mQuestionBank.length;
    //3~2~1~0~3~2~1~0...
    mCurrentIndex = (mCurrentIndex + mQuestionBank.length - 1) % mQuestionBank.length;

22.导入github工程,需要修改的文件

http://blog.csdn.net/onlysnail/article/details/45115093

23.判断所用API版本兼容性

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){//Build.VERSION_CODES.LOLLIPOP表示版本代号为LOLLIPOP


}

24.ImageView和ImageButton的真正区别

网上关于ImageView和ImageButton的区别讲的一头雾水,真相是ImageView在不设置监听事件时是不会阻挡到父容器的点击,而ImageButton即使只监听了父容器的点击事件,仍然默认监听点击,会遮挡点击效果 

 25:tomcat启动

由于tomcat和其他服务不同,似乎不会开机启动

#cd /usr/local/tomcat8/bin/

#./startup.sh

26:docker安装教程

http://blog.csdn.net/fgf00/article/details/51893771

27:linux卡死在登陆界面

你的profile文件出错了,用ctrl+alt F1进入命令行模式

岑忠满的博客新站点 https://cenzm.xyz
原文地址:https://www.cnblogs.com/cenzhongman/p/6036798.html