1、获取屏幕尺寸
Display display = getWindowManager().getDefaultDisplay();
display.getWidth()';//返回px值
display.getHeight();//返回px值
display.getRotation();//返回0或1,0表示竖屏,1表示横屏
2、设置界面不显示标题
以编程方式设置:
requestWindowFeature(Window.FEATURE_NO_TITLE);
在AndroidManifest.xml中设置全屏,以下代码写在<activity>中:
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
3、使用应用程序上下文
Contextcontext = getApplicationContext();
由于Activity类时从Context派生而来的,因此,在Activity类中编写代码时,可直接使用this对象,而不用显式地获取应用程序上下文,例如:
Intentintent = new Intent(Main.this , activity.class);
Intentintent = new Intent(getApplication , activity.class);
4、获取应用程序资源
Stringstring = getResources().getString(R.string.hello);