zoukankan      html  css  js  c++  java
  • android学习

    1。全屏显示,取消标题栏和状态栏

    Java代码 复制代码 收藏代码
    1. requestWindowFeature(Window.FEATURE_NO_TITLE);     //取消标题   
    2. getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,    
    3. WindowManager.LayoutParams.FLAG_FULLSCREEN);   //取消状态栏  
        requestWindowFeature(Window.FEATURE_NO_TITLE);     //取消标题
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
        WindowManager.LayoutParams.FLAG_FULLSCREEN);   //取消状态栏

    2.图片由浅到深显示。使用滤镜

    Java代码 复制代码 收藏代码
    1. AlphaAnimation alp = new AlphaAnimation(0.1f,1.0f);   //透明度由0.1到1.0渐变   
    2. alp.setDuration(3*1000);   //全部显示过程3秒钟   
    3. ImageView image = new ImageView(this);   
    4. image.startAnimation(alp);  //启动指定的绘制   
    5. alp.setAnimationListener(new AnimationListener() {         
    6.     @Override  
    7.     public void onAnimationStart(Animation animation) {}   
    8.     @Override  
    9.     public void onAnimationRepeat(Animation animation) {}   
    10.                
    11.     @Override  
    12.     public void onAnimationEnd(Animation animation) {   
    13.         //当显示完成之后才做某事   
    14.     }   
    15. });  
    AlphaAnimation alp = new AlphaAnimation(0.1f,1.0f);   //透明度由0.1到1.0渐变
    alp.setDuration(3*1000);   //全部显示过程3秒钟
    ImageView image = new ImageView(this);
    image.startAnimation(alp);  //启动指定的绘制
    alp.setAnimationListener(new AnimationListener() {		
    	@Override
    	public void onAnimationStart(Animation animation) {}
    	@Override
    	public void onAnimationRepeat(Animation animation) {}
    			
    	@Override
    	public void onAnimationEnd(Animation animation) {
    		//当显示完成之后才做某事
    	}
    });

    3。检测手机网络是否畅通

    Java代码 复制代码 收藏代码
    1. public static boolean checkNet(Context context){   
    2.     /*根据系统服务获取手机连接管理对象*/  
    3.     ConnectivityManager connectivity = (ConnectivityManager)context.   
    4.             getSystemService(Context.CONNECTIVITY_SERVICE);   
    5.     if(connectivity!=null){   
    6.         NetworkInfo info = connectivity.getActiveNetworkInfo();   
    7.         if(info!=null && info.isConnected()){      
    8.             //判断当前网络是否连接   
    9.             if(info.getState()==NetworkInfo.State.CONNECTED){   
    10.                 return true;   
    11.             }   
    12.         }   
    13.     }   
    14.     return false;   
    15.    }   
    16.   
    17.    如果网络不通,可使用下面的服务进入手机的网络配置   
    18.    startActivity(new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS));  
     public static boolean checkNet(Context context){
        	/*根据系统服务获取手机连接管理对象*/
        	ConnectivityManager connectivity = (ConnectivityManager)context.
        			getSystemService(Context.CONNECTIVITY_SERVICE);
        	if(connectivity!=null){
        		NetworkInfo info = connectivity.getActiveNetworkInfo();
        		if(info!=null && info.isConnected()){   
        			//判断当前网络是否连接
        			if(info.getState()==NetworkInfo.State.CONNECTED){
        				return true;
        			}
        		}
        	}
        	return false;
        }
    
        如果网络不通,可使用下面的服务进入手机的网络配置
        startActivity(new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS));

    4.关于提示alert

     (1) .使用toast

    Java代码 复制代码 收藏代码
    1. Toast tst =Toast.makeText(this,"text",Toast.LENGTH_SHORT);   
    2. tst.show();  
    Toast tst =Toast.makeText(this,"text",Toast.LENGTH_SHORT);
    tst.show();

     (2) 。使用一个alert dialog box

    Java代码 复制代码 收藏代码
    1. AlertDialog dialog = new AlertDialog.Builder(this).create();   
    2. dialog.setTitle("标题部分");   
    3. dialog.setMessage("提示消息");   
    4. dialog.setButton(DialogInterface.BUTTON_POSITIVE,"button value",    
    5.     new DialogInterface.OnClickListener() {   
    6.         public void onClick(DialogInterface dialog, int which) {   
    7.             //某操作   
    8.         }   
    9.     });   
    10. dialog.setButton(DialogInterface.BUTTON_NEGATIVE,"button value",    
    11.     new DialogInterface.OnClickListener() {   
    12.         public void onClick(DialogInterface dialog, int which) {   
    13.             //某操作   
    14.         }   
    15.     });   
    16. dialog.setButton(DialogInterface.BUTTON_NEUTRAL,"button value",    
    17.     new DialogInterface.OnClickListener() {   
    18.         public void onClick(DialogInterface dialog, int which) {   
    19.             //某操作   
    20.         }   
    21.     });  
    AlertDialog dialog = new AlertDialog.Builder(this).create();
    dialog.setTitle("标题部分");
    dialog.setMessage("提示消息");
    dialog.setButton(DialogInterface.BUTTON_POSITIVE,"button value", 
    	new DialogInterface.OnClickListener() {
    		public void onClick(DialogInterface dialog, int which) {
    			//某操作
    		}
    	});
    dialog.setButton(DialogInterface.BUTTON_NEGATIVE,"button value", 
    	new DialogInterface.OnClickListener() {
    		public void onClick(DialogInterface dialog, int which) {
    			//某操作
    		}
    	});
    dialog.setButton(DialogInterface.BUTTON_NEUTRAL,"button value", 
    	new DialogInterface.OnClickListener() {
    		public void onClick(DialogInterface dialog, int which) {
    			//某操作
    		}
    	});

      这里完善一下alertdialog,由于内容很多这里只贴一下图加点简单介绍。

    ①list dialog即一个dialog中含有一个列表


    ②一个含有进度条的dialog


    ③dialog中含有单选列表   相当于radio组


    ④dialog中多选按钮列表,相当于checkBox组


    ⑤自定义dialog中的布局,图中登录框为自定义的视图


    顺便说一句。dialog列表中的数据还可以冲数据库中读取,因为builder中有方法

     setMultiChoiceItems(Cursor cursor, String isCheckedColumn, String labelColumn,.....可以传递一个cursor

    (3).使用Notification in Status Bar.关键代码如下

       第一种方法普遍的Notification:

    Java代码 复制代码 收藏代码
    1.       //第一步:创建notification管理类NotificationManager   
    2. String ns = Context.NOTIFICATION_SERVICE;   
    3. NotificationManager manager = (NotificationManager)this.getSystemService(ns);   
    4.        
    5. //二,创建notification实例,参数1为显示的图片,2为提示文字,3是什么时候执行   
    6. Notification notification = new Notification(R.drawable.dback, "下载完成", System.currentTimeMillis());   
    7.        
    8. //定义notification的额外信息和intent   
    9. Intent intent = new Intent(this,StatusBarActivity.class);   
    10. PendingIntent pendingIntent = PendingIntent.getActivity(this0, intent, PendingIntent.FLAG_UPDATE_CURRENT);   
    11. notification.setLatestEventInfo(this"下载""下载完成", pendingIntent);   
    12.        
    13. //传入notification到NotificationManager中   
    14. manager.notify(notiId, notification);  
           //第一步:创建notification管理类NotificationManager
    	String ns = Context.NOTIFICATION_SERVICE;
    	NotificationManager manager = (NotificationManager)this.getSystemService(ns);
    		
    	//二,创建notification实例,参数1为显示的图片,2为提示文字,3是什么时候执行
    	Notification notification = new Notification(R.drawable.dback, "下载完成", System.currentTimeMillis());
    		
    	//定义notification的额外信息和intent
    	Intent intent = new Intent(this,StatusBarActivity.class);
    	PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    	notification.setLatestEventInfo(this, "下载", "下载完成", pendingIntent);
    		
    	//传入notification到NotificationManager中
    	manager.notify(notiId, notification);
    

       第二种方法。定制自己的notification提示信息

    Java代码 复制代码 收藏代码
    1.       //自己使用布局定制一个提示信息   
    2. String ns = Context.NOTIFICATION_SERVICE;   
    3. NotificationManager manager = (NotificationManager)this.getSystemService(ns);   
    4. Notification notification = new Notification(R.drawable.dback, "自制提示信息", System.currentTimeMillis());   
    5.        
    6. RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_notification_layout);  //指定自己的提示ui布局文件   
    7. contentView.setImageViewResource(R.id.image, R.drawable.notification_image);   
    8. contentView.setTextViewText(R.id.text, "Hello, this message is in a custom expanded view");   
    9. notification.contentView = contentView;   
    10.        
    11. Intent notificationIntent = new Intent(this, StatusBarActivity.class);   
    12. PendingIntent contentIntent = PendingIntent.getActivity(this0, notificationIntent, 0);   
    13. notification.contentIntent = contentIntent;   
    14.        
    15. manager.notify(notiId, notification);  
           //自己使用布局定制一个提示信息
    	String ns = Context.NOTIFICATION_SERVICE;
    	NotificationManager manager = (NotificationManager)this.getSystemService(ns);
    	Notification notification = new Notification(R.drawable.dback, "自制提示信息", System.currentTimeMillis());
    		
    	RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_notification_layout);  //指定自己的提示ui布局文件
    	contentView.setImageViewResource(R.id.image, R.drawable.notification_image);
    	contentView.setTextViewText(R.id.text, "Hello, this message is in a custom expanded view");
    	notification.contentView = contentView;
    		
    	Intent notificationIntent = new Intent(this, StatusBarActivity.class);
    	PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    	notification.contentIntent = contentIntent;
    		
    	manager.notify(notiId, notification);

    5.解决android软键盘挡住控件方法:

    Java代码 复制代码 收藏代码
    1. getWindow().setSoftInputMode(modes);   
    2. /*moeds有三个值:默认WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED  
    3.  WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE  
    4. WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN  
    5. modes为第二个或第三个可以解决问题  
    6. */  
    getWindow().setSoftInputMode(modes);
    /*moeds有三个值:默认WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED
     WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
    WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN
    modes为第二个或第三个可以解决问题
    */
    

    6.使用wake locks

     开启你的手机应用,当你一定时间不与你的手机交互时,手机屏幕将会暗淡下去。使用wake locks 会使手机屏幕一直处于激活状态。

    使用方式:首先在manifestw文件中配置 user-perssion  值为android.permission.WAKE_LOCK。

    Java代码 复制代码 收藏代码
    1. 然后:PowerManager powerManager =   
    2.                      (PowerManager)context.getSystemService(Context.POWER_SERVICE);   
    3. WakeLock wakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "My Lock");  
    然后:PowerManager powerManager =
                         (PowerManager)context.getSystemService(Context.POWER_SERVICE);
    WakeLock wakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "My Lock");

    开启wake locks使用方法:wakeLock.acquire();

    当你的应用暂停或者退出时释放:wakeLock.release();

    一般我们在activity中的onCreate方法中创建wakeLock对象

    在onResume方法中调用WakeLock.acquire()

    在onPause方法中调用wakeLock.release();

    7.关于drawBitmap(Bitmap bitmap, Rect src, Rect dst, Paint paint)方法

    这个方法我看了很久,并做了一些测试,终于弄明白了。

    这个方法可以用来剪辑一张图片的一部分,即当我们把一组图片做成一张时,我们可以用此方法来剪辑出单个图片。

    bitmap的默认坐标是0,0.我们可以在此基础上剪图片。矩形src为我们所剪辑的图片的包围框,即你所剪的图片,如果为空,就是整张图片。矩形dst容纳你所剪的图片,然后根据此矩形的位置设置图片的位置。此参数不能为空。当你剪的图片大小大于dst时,多余的部分将不会显示。

    其他参考
    http://www.cnblogs.com/zhengtao/articles/1930802.html

    8.设置自己的Mp3为铃声

    Java代码 复制代码 收藏代码
    1. String filePath = MP3的sd卡地址   
    2. RingtoneManager.setActualDefaultRingtoneUri(this,    
    3.                     RingtoneManager.TYPE_RINGTONE, Uri.parse("file://"+filePath));  
    String filePath = MP3的sd卡地址
    RingtoneManager.setActualDefaultRingtoneUri(this, 
    					RingtoneManager.TYPE_RINGTONE, Uri.parse("file://"+filePath));

    9. 设置背景透明度及其颜色

     转:

    半透明<Button android:background="#e0000000" ... />
    透明<Button android:background="#00000000" ... />
    颜色和不透明度 (alpha) 值以十六进制表示法表示。任何一种颜色的值范围都是 0 到 255(00 到 ff)。对于 alpha,00 表示完全透明,ff 表示完全不透明。表达式顺序是“aabbggrr”,其中aa=alpha(00 到 ff);bb=blue(00 到 ff);gg=green(00 到 ff);rr=red(00 到 ff)。例如,如果您希望对某叠加层应用不透明度为 50% 的蓝色,则应指定以下值:7fff0000

    Java代码 
    View v = findViewById(R.id.content);//找到你要设透明背景的layout 的id 
    v.getBackground().setAlpha(100);//0~255透明度值 ,0为完全透明,255为不透明

    10.关于android杀毒软件的实现及其原理

     
    http://blog.csdn.net/furongkang/article/details/6915644
    • 大小: 22.1 KB
    • 大小: 18.5 KB
    • 大小: 23.1 KB
    • 大小: 31.5 KB
    • 大小: 20 KB

    ............暂时这几个,以后会追加。

  • 相关阅读:
    用CSS3实现上下左右箭头
    让input框只能输入数字
    给内联元素设置宽高的几种方式
    当文本溢出包含的元素时加省略号之text-overflow
    通过box盒子模型给元素内容设置居中
    CSS3中的字体rem
    封装一个取消事件冒泡的方法
    HTML5 web workes实现多线程
    通过imeMode禁用键盘只能输入数字
    jquery的children方法和css3选择器配合使用
  • 原文地址:https://www.cnblogs.com/qingblog/p/2521697.html
Copyright © 2011-2022 走看看