应用程序不会在全屏显示和崩溃

时间:2014-09-20 19:35:16

标签: android themes fullscreen manifest

我正在全屏制作一个我想要的应用程序(好吧,它可以有顶部的图标,如信号,电池等,但没有标题栏)。它是在风景中,我在我的" ye olde"三星Galaxy Ace。

当使用常规的android:theme =" @ style / AppTheme它很好,但有标题栏。每当我尝试通常的解决方案(将其更改为全屏,没有标题栏样式 - 没有代码在我身上)时,它会加载,但屏幕本身保持空白,直到它崩溃几秒钟后。

我将粘贴相关文件和logcat ...

...清单

<?xml version="1.0" encoding="utf-8"?>

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="19" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.myname.MainActivity"
        android:screenOrientation="landscape"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.NoTitleBar" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

... MainActivity

    package com.example.myname;

import com.example.simpletimer.R;

import android.content.Context;
import android.os.Handler;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;



import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.os.Build;

public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);

//        if (savedInstanceState == null) {
//            getSupportFragmentManager().beginTransaction()
//                    .add(R.id.container, new PlaceholderFragment())
//                    .commit();
//        }
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    /**
     * A placeholder fragment containing a simple view.
     */
    public static class PlaceholderFragment extends Fragment {

        public PlaceholderFragment() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_main, container, false);
            return rootView;
        }
    }

}

... logcat中

09-20 20:37:56.890: I/ApplicationPackageManager(15836): cscCountry is not German : BTU
09-20 20:37:56.960: W/dalvikvm(15836): threadid=1: thread exiting with uncaught exception (group=0x40018578)
09-20 20:37:56.984: E/AndroidRuntime(15836): FATAL EXCEPTION: main
09-20 20:37:56.984: E/AndroidRuntime(15836): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.simpletimer/com.example.myname.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
09-20 20:37:56.984: E/AndroidRuntime(15836):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
09-20 20:37:56.984: E/AndroidRuntime(15836):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
09-20 20:37:56.984: E/AndroidRuntime(15836):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
09-20 20:37:56.984: E/AndroidRuntime(15836):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
09-20 20:37:56.984: E/AndroidRuntime(15836):    at android.os.Handler.dispatchMessage(Handler.java:99)
09-20 20:37:56.984: E/AndroidRuntime(15836):    at android.os.Looper.loop(Looper.java:130)
09-20 20:37:56.984: E/AndroidRuntime(15836):    at android.app.ActivityThread.main(ActivityThread.java:3687)
09-20 20:37:56.984: E/AndroidRuntime(15836):    at java.lang.reflect.Method.invokeNative(Native Method)
09-20 20:37:56.984: E/AndroidRuntime(15836):    at java.lang.reflect.Method.invoke(Method.java:507)
09-20 20:37:56.984: E/AndroidRuntime(15836):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
09-20 20:37:56.984: E/AndroidRuntime(15836):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
09-20 20:37:56.984: E/AndroidRuntime(15836):    at dalvik.system.NativeStart.main(Native Method)
09-20 20:37:56.984: E/AndroidRuntime(15836): Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
09-20 20:37:56.984: E/AndroidRuntime(15836):    at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:111)
09-20 20:37:56.984: E/AndroidRuntime(15836):    at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:98)
09-20 20:37:56.984: E/AndroidRuntime(15836):    at com.example.myname.MainActivity.onCreate(MainActivity.java:30)
09-20 20:37:56.984: E/AndroidRuntime(15836):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-20 20:37:56.984: E/AndroidRuntime(15836):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
09-20 20:37:56.984: E/AndroidRuntime(15836):    ... 11 more

非常感谢任何帮助 - 谢谢!

编辑和我的答案

好的,我尝试了下面列出的两种解决方案,但遗憾的是无法找到有效的主题,而且我的资源中找不到发布的主题。所以我将以下代码放在我的MainActivity中:

ActionBar actionBar = getSupportActionBar();
actionBar.hide();

这就在

之后
setContentView(R.layout.activity_main);

我仍然接受以下两个答案(如果可以的话),虽然他们确实指出了我正确的方向,但我无法让他们工作(这是我的错),我&#39 ;我相信他们会帮助别人。

2 个答案:

答案 0 :(得分:1)

Logcat说:

  

您需要使用Theme.AppCompat主题(或后代)   活性。

例如,在清单中使用Theme.AppCompat.Light.NoActionBar此活动

答案 1 :(得分:1)

如果问题相当清楚,那么堆栈跟踪。您正在尝试使用不适用于v7兼容性库的主题。

您需要使用Theme.AppCompat主题或从Theme.AppCompat派生的主题。

或者,如果你真的不需要从ActionBarActivity扩展,你可以简单地从Activity扩展。

来自其他帖子的更多信息:

You need to use a Theme.AppCompat theme (or descendant) with this activity