zoukankan      html  css  js  c++  java
  • Android之基本常见知识(持续更新)

     

    //能够取得屏幕的信息 

    DisplayMetrics dm = new DisplayMetrics(); 

        getWindowManager().getDefaultDisplay().getMetrics(dm);

    dm.widthPixels;                //取得宽像素
        dm.heightPixels;       //取得高像素

    //获取当地的日历 

    Calendar c=Calendar.getInstance();
        mYear=c.get(Calendar.YEAR);//获取年份
        mMonth=c.get(Calendar.MONTH);//获取月份
     mDay=c.get(Calendar.DAY_OF_MONTH);//获取号数
        mHour=c.get(Calendar.HOUR_OF_DAY);//获取小时

        mMinute=c.get(Calendar.MINUTE); //获取分钟

    //把EditText的内容设为可视或隐藏

    /* 设定EditText的内容为可见的 */

         editText.setTransformationMethod(

         HideReturnsTransformationMethod.getInstance());

         /* 设定EditText的内容为隐藏的 */

         editText.setTransformationMethod(

         PasswordTransformationMethod.getInstance()); 
    //启动activity时不自动弹出软键盘

            getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);  

    //设置全屏(在setContentView之前设置)
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

     
    //设置取消全屏

    WindowManager.LayoutParams attrs = getWindow().getAttributes();  

    attrs.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN); getWindow().setAttributes(attrs); getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);

    //设置无标题(在setContentView之前设置)

            requestWindowFeature(Window.FEATURE_NO_TITLE); 

    //设置禁止手机横屏(在setContentView之前设置)

    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR); 

    //调用手机默认的摄像功能,而且可以设定储存位置

    Intent i = new Intent("android.media.action.IMAGE_CAPTURE");  

    i.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(Environment .getExternalStorageDirectory(),"pic.jpg")));

    //解决中文乱码方法 

    A. 使用getBytes("") 来对汉字进行重编码,得到它的字节数组

    B. 再使用new String(Bytes[] , "解码方式")  来对字节数组进行相应的解码

    //在Android中轻松实现横竖屏的布局 

    竖屏的布局一般在layout下面设置;横屏的布局则在layout的同等级文件夹创建名字layout-land的文件夹。模拟器可以使用Ctrl+F11进行快速切换。 

    //Android横竖屏切换不重启Activity

    androidmanifest.xml中的activit元素加入这个属性android:configChanges="orientation|keyboardHidden" 

    然后在Activity中重载以下方法:

    复制代码
              public void onConfigurationChanged(Configuration newConfig) {

         // TODO Auto-generated method stub
      if (newConfig.orientation==Configuration.ORIENTATION_LANDSCAPE) {
                setContentView(R.layout.imageswitch);
                //横屏
            } else {
                setContentView(R.layout.editcontact);//竖屏
            }
             super.onConfigurationChanged(newConfig);

    }   

    复制代码

        
    卸载程序:

    Uri packageURI = Uri.parse("package:com.demo.CanavaCancel");   

    Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);   
    startActivity(uninstallIntent);


    安装apk:

    String str = "/CanavaCancel.apk";
    String fileName = Environment.getExternalStorageDirectory() + str;
    Intent intent = new Intent(Intent.ACTION_VIEW);
     intent.setDataAndType(Uri.fromFile(new File(fileName)), "application/vnd.android.package-archive");

    startActivity(intent)

  • 相关阅读:
    在使用IO流时该选择何种流对象
    对Java中的File类的一些理解
    AlarmManager实现闹钟功能
    Android 中 Movie 类显示GIF图片
    Java对象序列化和serialVersionUID [转载]
    Git常用命令行操作
    Android中常用的编码和解码(加密和解密)的问题
    Android apk反编译 和 防止反编译
    Bitmap 图片二次采样 【转载】
    Android:瀑布流效果 的简单实现
  • 原文地址:https://www.cnblogs.com/raffeale/p/4591137.html
Copyright © 2011-2022 走看看