Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android full screen layout position

I got a problem with setting an action to full screen. When I set an action to full screen, the layout was shifted down, it does not draw from the top edge of screen. But it will be fix by itself when I press menu button and the menu shown.

I set it to full screen by following code: setTheme(android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);

I also make the wallpaper can be visible and hide title bar. It was tested on android 2.1 and 2.2

simplified Code:

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>

Result:

Result

Update:

I found that if I replace the EditText to TextView, it works properly. If the EditText is the first View to show, the layout will be shifted down.

like image 890
user554712 Avatar asked Mar 22 '26 02:03

user554712


1 Answers

I guess it's because you execute super.onCreate after your settings. Try the following:

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);
    }
}
like image 51
Bevor Avatar answered Mar 24 '26 18:03

Bevor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!