android的小细节

全屏去状态栏 
Java代码  
Window window = getWindow();  
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);  
window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);  

/设置为无标题栏 

Java代码  
requestWindowFeature(Window.FEATURE_NO_TITLE);  
  

//设置为全屏模式 

Java代码  
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);    


流的处理 
Java代码  
InputStream is = getResources().openRawResource(R.drawable.icon);    
        //decode    
 Bitmap mBitmap = BitmapFactory.decodeStream(is);    


获取屏幕的宽和高 
Java代码  
int screenWidth;    
int screenHeight;    
    
WindowManager windowManager = getWindowManager();    
    
Display display = windowManager.getDefaultDisplay();    
screenWidth = display.getWidth();    
screenHeight = display.getHeight();  


固定横竖屏 
在AndroidManifest.xml里面配置一下就可以了。加入这一行android:screenOrientation="landscape"。 
例如(landscape是横向,portrait是纵向): 
Java代码  
<activity android:name=".GamePlay"    
                android:screenOrientation="portrait"></activity>   


Android View添加 Listener 小技巧示例 
http://rayleung.iteye.com/blog/539190 

动画 
Java代码  
Animation rotateAnimation =  
        AnimationUtils.loadAnimation(this, R.anim.rotate1);  

资源 
Java代码  
Resources res = context.getResources();  



一些牛人的blog 
http://rayleung.iteye.com/ 


屏幕切换时的问题 
获取屏幕的方向: 

默认情况下,当屏幕方面切换时,activity的onCreate()方法会被重新调用,所以可以在其中通过以下代码来读取屏的方向: 

Java代码  
public void onCreate() {    
  if(this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {    
     Log.i("info", "landscape");    
  } else if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {    
     Log.i("info", "portrait");    
  }    
}    


如果在androidmanifest.xml中加入配置 
android:configChanges="orientation|keyboardHidden|navigation 
当屏幕翻转时,Activity就不会重复的调用onCreate()、onPause()和onResume(). 
而是调用onConfigurationChanged(Configuration newConfig) 

测试时经常用到 
Java代码  
Toast.makeText(testActivity.this, "click button", Toast.LENGTH_SHORT).show();  


bitmap 和 drawable 互换 
Java代码  
((BitmapDrawable)res.getDrawable(R.drawable.youricon)).getBitmap();  
		// 设置没有标题
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		// 设置全屏
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		// 保持背光常亮的设置
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
				WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);


你可能感兴趣的:(android的小细节)