Android 不显示标题栏和全屏的设置方法
1.在Manifest.xml中设置
不显示标题栏
android:theme="@android:style/Theme.NoTitleBar"
全屏
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
2.在代码中实现
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
Android应用开发界面顶部上有灰条,用来显示项目名称。这个应用名称是可以更改的,在strings.xml中,就可以设定 <string name="app_name">应用名称</string>。如果不显示的话,加上一个语句就行了:requestWindowFeature(Window.FEATURE_NO_TITLE);
经过实践操作具体添加位置:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);// 填充标题栏
setContentView(R.layout.main);
requestWindowFeature();
这句需要在setContentView之前使用才能生效。
3
/**
* 全屏切换
*/
public void fullScreenChange() {
SharedPreferences mPreferences = PreferenceManager
.getDefaultSharedPreferences(this);
boolean fullScreen = mPreferences.getBoolean("fullScreen", false);
WindowManager.LayoutParams attrs = getWindow().getAttributes();
System.out.println("fullScreen的值:" + fullScreen);
if (fullScreen) {
attrs.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().setAttributes(attrs);
// 取消全屏设置
getWindow().clearFlags(
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
mPreferences.edit().putBoolean("fullScreen", false).commit();
} else {
attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
getWindow().setAttributes(attrs);
getWindow().addFlags(
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
mPreferences.edit().putBoolean("fullScreen", true).commit();
}
}
不能横屏,在AndroidMainFest.aml中添加Activity定义的时候
android:name="com.example.testcontextmenu.Test_Contextmenu"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/app_name"
android:screenOrientation="portrait"