如何在Android中设置XML全屏

Sus*_*shi 16 xml android

如何在XML中创建全屏模式,而不管其中的内容有多小?

这是我的"show.xml"代码:

<LinearLayout android:orientation="vertical"
android:layout_height="wrap_content" android:layout_width="fill_parent"
android:layout_gravity="center">    

<Button android:id="@+id/ok_btn" android:layout_height="fill_parent"
android:layout_width="fill_parent" android:typeface="sans" android:text="ok"></Button>

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

我想像另一个全屏幕页面一样显示它,黑色背景,像main.xml.在这种情况下,它就像一个弹出屏幕.删除或更改android:layout_width和android:layout_heigh不起作用.请帮忙!:(

Mar*_*Nuc 40

Afaik你不能在xml中全屏.你有两个选择:

1)活动部分中的AndroidManifest.xml

android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 
Run Code Online (Sandbox Code Playgroud)

2)在onCreate()的代码中

requestWindowFeature( Window.FEATURE_NO_TITLE );

getWindow().setFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN,
                      WindowManager.LayoutParams.FLAG_FULLSCREEN );
Run Code Online (Sandbox Code Playgroud)


Fel*_*lix 15

由于其他答案对我不起作用:


<style name="AppTheme.Fullscreen">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowFullscreen">true</item>
</style>
Run Code Online (Sandbox Code Playgroud)

将此样式添加到styles.xml


<activity
    android:name=".TitlesActivity"
    android:theme="@style/AppTheme.Fullscreen">
Run Code Online (Sandbox Code Playgroud)

确保您在AndroidManifest.xml中的活动引用您的主题.