[英]Android full screen layout position
將操作設置為全屏時出現問題。 當我將動作設置為全屏時,布局向下移動,它不會從屏幕的上邊緣繪制。 但是當我按下菜單按鈕和顯示的菜單時,它將自行修復。
我通過以下代碼將其設置為全屏: setTheme(android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
我也讓壁紙可見並隱藏標題欄。 它在Android 2.1和2.2上測試過
簡化代碼:
TestActivity.java:
package com.test.fullscreen;
import android.app.Activity;
import android.os.Bundle;
import android.view.WindowManager;
public class TestActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
setTheme(android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<EditText
android:id="@+id/inputBox"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#66303030"
android:cursorVisible="true"
android:hint="Text"
android:paddingLeft="7dp"
android:paddingRight="17dp"
android:textColor="#ffffff"
android:textSize="24dp" />
</LinearLayout>
AndroidManifest.xml中
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.fullscreen"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="7" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="@string/app_name"
android:name=".TestActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
結果:
更新:
我發現如果我將EditText
替換為TextView
,它可以正常工作。 如果EditText是第一個要顯示的View
,則布局將向下移動。
我想這是因為你在設置后執行super.onCreate。 請嘗試以下方法:
public class TestActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setTheme(android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
setContentView(R.layout.main);
}
}
嘗試:
requestWindowFeature(FEATURE_NO_TITLE);
在Activity的onCreate
調用setContentView(view)
之前,必須先調用requestWindowFeature 。 還請致電以下人員:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.