制作一个应用程序全屏

制作一个应用程序全屏

本文介绍了安卓:制作一个应用程序全屏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是我可以做一个新的空白的活动,由机器人工作室的最新版本创建的,以获取应用程序出现全屏最简单的变化?

我想创建一个全屏幕的Andr​​oid应用程序。我正与Android的工作室。这个帖子建议我增加一行,如...

安卓主题=@安卓风格/ Theme.Holo.Light.NoActionBar.Fullscreen

...到AndroidManifest.xml文件,如下图所示:

 < XML版本=1.0编码=UTF-8&GT?;
    <舱单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
            包=com.lexogram.james.blackslate>

            <应用
                    机器人:allowBackup =真
                    机器人:图标=@可绘制/ ic_launcher
                    机器人:标签=@字符串/ APP_NAME
                    机器人:主题=@风格/ AppTheme>
                    <活动
                            机器人:名称=com.lexogram.james.blackslate.MainActivity
                            机器人:标签=@字符串/ APP_NAME
                            机器人:主题=@安卓风格/ Theme.Holo.Light.NoActionBar.Fullscreen>
                            <意向滤光器>
                                    <作用机器人:名称=android.intent.action.MAIN/>

                                    <类机器人:名称=android.intent.category.LAUNCHER/>
                            &所述; /意图滤光器>
                    < /活性GT;
            < /用途>

    < /舱单>
 

当我这样做,应用程序编译,但它崩溃上推出。如果我删除行,应用程序运行正常,但随着操作栏和标题栏一样,也注意到其他用户。

这是我创造一个Android应用程序第一次尝试,所以我的应用程序难以从原来的Hello World示例改变。

编辑:我创建了一个新的项目,并取得了仅此一改变它。这里是从错误日志摘录:

 致命异常:主要
    java.lang.RuntimeException的:无法启动的活动ComponentInfo {com.lexogram.james.test / com.lexogram.james.test.MainActivity}:java.lang.IllegalStateException:您需要使用Theme.AppCompat主题(或后代)这一活动。
        在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2669)...
 

注:我正在测试一个老的三星SGH-T499Y,运行Android 2.2(升级Froyo)

解决方案

您收到此问题,因为活动你试图运用安卓主题=@安卓风格/ Theme.Holo .Light.NoActionBar.Fullscreen> 来是扩大ActionBarActivity这就要求AppCompat主题适用

活动而不是 ActionBarActivity

扩展您的活动

您可能需要相应地改变你的Java类点点。

如果你想删除的状态栏太前的setContentView然后用这个(布局) onCreateView 方法

  getWindow()。setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FULLSCREEN);
 

What is the simplest change that I can make to a new Blank Activity, as created by the latest version of Android Studio, to get the app to appear fullscreen?

I want to create a fullscreen Android application. I'm working with Android Studio.This post suggests that I add a line such as ...

android:theme="@android:style/Theme.Holo.Light.NoActionBar.Fullscreen"

... to the AndroidManifest.xml file, as shown below:

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
            package="com.lexogram.james.blackslate" >

            <application
                    android:allowBackup="true"
                    android:icon="@drawable/ic_launcher"
                    android:label="@string/app_name"
                    android:theme="@style/AppTheme" >
                    <activity
                            android:name="com.lexogram.james.blackslate.MainActivity"
                            android:label="@string/app_name"
                            android:theme="@android:style/Theme.Holo.Light.NoActionBar.Fullscreen">
                            <intent-filter>
                                    <action android:name="android.intent.action.MAIN" />

                                    <category android:name="android.intent.category.LAUNCHER" />
                            </intent-filter>
                    </activity>
            </application>

    </manifest>

When I do this, the app compiles but it crashes on launch. If I remove the line, the app runs fine, but with the action bar and a title bar, as also noted by other users.

This is my first attempt at creating an Android app, so my app is hardly altered from the original Hello World example.

EDIT:I created a new project, and made just this one change to it. Here is an extract from the error log:

FATAL EXCEPTION: main
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.lexogram.james.test/com.lexogram.james.test.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2669)...

NOTE: I am testing on a old Samsung SGH-T499Y, running Android 2.2 (Froyo)

解决方案

You are getting this problem because the activity you are trying to apply the android:theme="@android:style/Theme.Holo.Light.NoActionBar.Fullscreen"> to is extending ActionBarActivity which requires the AppCompat theme to be applied.

Extend your activity from Activity rather than from ActionBarActivity

You might have to change your Java class accordingly little bit.

If you want to remove status bar too then use this before setContentView(layout) in onCreateView method

        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FULLSCREEN);

这篇关于安卓:制作一个应用程序全屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 12:47