标签:android enter 设备 his 自己 tutorial 标题栏 pac ble
//去标题栏(在onCreate中)
requestWindowFeature(Window.FEATURE_NO_TITLE);
//设置全屏(在onCreate中)
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
//横竖屏幕(在onResume中)
//手机屏幕的朝向有11个可选值,分别如下
//SCREEN_ORIENTATION_BEHIND:
Activity堆栈中当前Activity下面的那个Activity的方向
//SCREEN_ORIENTATION_LANDSCAPE: 横屏(风景照) ,显示时宽度大于高度
//SCREEN_ORIENTATION_PORTRAIT: 竖屏 (肖像照) , 显示时高度大于宽度
//SCREEN_ORIENTATION_NOSENSOR: 忽略物理感应器——即显示方向与物理感应器无关
//SCREEN_ORIENTATION_SENSOR: 由物理感应器决定显示方向,它取决于用户如何持有设备
//SCREEN_ORIENTATION_UNSPECIFIED: 默认值,由Android系统自己选择适当的方向
//SCREEN_ORIENTATION_USER: 用户当前的首选方向
//SCREE……
setRequestedOrientation(ActivityInfo. SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
横竖屏切换不重启Activity
配置了这个属性,当我们横竖屏切换的时候会直接调用onCreate方法中的onConfigurationChanged方法,而不会重新执行onCreate方法。
<activity android:name=".TestActivity" android:label="@string/app_name" android:configChanges="keyboardHidden|orientation"> </activity> |
@Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); if(newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE){ tv.setText("横屏"); }else{……} } |
Toast
Private static Toast mToast; public static void showToast(Context context, String msg) { if (mToast == null) { mToast = Toast.makeText(context, msg, Toast.LENGTH_SHORT); } else { mToast.setText(msg); } mToast.show(); } |
样式全解析:http://android.tgbus.com/Android/tutorial/201103/346236.shtml
Activity跳转 ,清空Activity栈
我们知道Android的窗口类提供了历史栈,我们可以通过stack的原理来巧妙的实现,这里我们在A窗口打开B窗口时在Intent中直接加入标志Intent.FLAG_ACTIVITY_CLEAR_TOP,这样开启B时将会清除该进程空间的所有Activity。
在A窗口中使用下面的代码调用B窗口:
Intent intent
= newIntent(); startActivity(intent); |
接下来在B窗口中需要退出时直接使用finish()方法即可全部退出。
自定义Activity栈
public class ScreenManager { private static Stack<Activity> activityStack; private static ScreenManager instance; private ScreenManager(){ } public static ScreenManager getScreenManager(){ if( instance== null) instance= new ScreenManager(); return instance; } public void popActivity(){ Activity activity= activityStack.lastElement(); if(activity!= null){ activity.finish(); activity= null; } } public void popActivity(Activity activity){ if(activity!= null){ activity.finish(); activityStack.remove(activity); activity= null; } } public Activity currentActivity(){ Activity activity= activityStack.lastElement(); return activity; } public void pushActivity(Activity activity){ if( activityStack== null) activityStack= new Stack<Activity>(); activityStack.add(activity); } public void popAllActivityExceptOne( Class cls){ while(true ){ Activity activity=currentActivity(); if(activity== null) break; if(activity.getClass().equals(cls) ) break; popActivity(activity); } } } |
标签:android enter 设备 his 自己 tutorial 标题栏 pac ble
原文地址:http://www.cnblogs.com/keyarchen/p/6025903.html