Android开发FAQ之一

Android开发FAQ之一

 

1. 如何隐藏标题栏和状态栏

// no status bar
final Window win = getWindow();
win.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);

// no title bar
requestWindowFeature(Window.FEATURE_NO_TITLE);

2.  如何重启和关闭Activity

重启

Intent intent = new Intent();
intent.setClass(this, getClass());
startActivity(intent);
finish();

关闭

finish();

3. 固定Activity的屏幕方向

在AndroidManifest.xml的Activity标签内加入

android:screenOrientation=”landscape” 或者 android:screenOrientation=”portrait”

4. 打印日志信息

在android中,用System.out.println是无效的,要用Log.v(TAG, “xxx …”);
分别是Log.v 、 Log.d 、 log.i、 log.w、 log.e。使用Log打印的日志通过LogCat可以看到。

5. 带图标的菜单

menu.add(0, 0, 0, “New”).setIcon(R.drawable.menu_new);

大量标准的图标可以在sdk的platforms/android-1.5/data/res/drawable里找到

你可能感兴趣的:(android,xml)