Android: making a fullscreen application

匿名 (未验证) 提交于 2019-12-03 01:18:02

问题:

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:

    

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)

回答1:

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); 


回答2:

just do this in your manifest file in your activity tag

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


回答3:

Just add the following attribute to your current theme:

true

For example:



回答4:

in my case all works fine. See in logcat. Maybe logcat show something that can help you to resolve your problem

Anyway you can try do it programmatically:

 public class ActivityName extends Activity {         @Override         public void onCreate(Bundle savedInstanceState) {             super.onCreate(savedInstanceState);             // remove title             requestWindowFeature(Window.FEATURE_NO_TITLE);             getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,             WindowManager.LayoutParams.FLAG_FULLSCREEN);             setContentView(R.layout.main);         }  } 


回答5:

Update Answer I added android:windowIsTranslucent in case you have white screen in start of activity

just create new Style in values/styles.xml

from your AndroidManifest.xml add style to your activity

android:theme="@style/AppTheme"

to be like this



回答6:

In onCreate call

requestWindowFeature(Window.FEATURE_NO_TITLE); // for hiding title  getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,                              WindowManager.LayoutParams.FLAG_FULLSCREEN); 


回答7:

I recently had the exact same issue and benefitted from the following post as well (in addition to Rohit5k2's solution above):

https://bsgconsultancy.wordpress.com/2015/09/13/convert-any-website-into-android-application-by-using-android-studio/

In Step 3, MainActivity extends Activity instead of ActionBarActivity (as Rohit5k2 mentioned). Putting the NoTitleBar and Fullscreen theme elements into the correct places in the AndroidManifest.xml file is also very important (take a look at Step 4).



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!