如何让sdk 9 android app全屏失败

时间:2015-03-15 13:51:23

标签: android android-layout android-studio

好的,我的所有代码,但是当我尝试运行时它失败了

这里有java代码

package com.monstermmorpg.pokemon;

import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageButton;

public class Pokemon extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pokemon);
        addListenerOnButton();
    }

    private void addListenerOnButton() {

        ImageButton imgButton = (ImageButton) findViewById
                (R.id.imageButton_register);

        imgButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Uri uri = Uri.parse("http://www.monstermmorpg.com/Register");
                Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                startActivity(intent);
            }
        });
    }
}

下面的Manifest.xml

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

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
    <activity
        android:name=".Pokemon"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

下面的Activity.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Pokemon"
android:background="@color/background_floating_material_dark">

<ImageButton
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/imageButton_register"
    android:background="@null"
    android:src="@drawable/image_button"
    android:adjustViewBounds="true"
    android:scaleType="centerInside"
    android:layout_centerInParent="true"
    />

预览仍然不是全屏,但是当我尝试在真实设备上模拟或运行时,它会失败

这里模拟下面的logcat日志

    03-15 15:45:58.043    2653-2653/com.monstermmorpg.pokemon E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.monstermmorpg.pokemon, PID: 2653
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.monstermmorpg.pokemon/com.monstermmorpg.pokemon.Pokemon}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
            at android.app.ActivityThread.access$800(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
     Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
            at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:152)
            at android.support.v7.app.ActionBarActivityDelegateBase.onCreate(ActionBarActivityDelegateBase.java:149)
            at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:123)
            at com.monstermmorpg.pokemon.Pokemon.onCreate(Pokemon.java:16)
            at android.app.Activity.performCreate(Activity.java:5933)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
            at android.app.ActivityThread.access$800(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
03-15 15:45:58.046    2653-2660/com.monstermmorpg.pokemon E/art﹕ Failed sending reply to debugger: Broken pipe
03-15 15:45:58.046    2653-2660/com.monstermmorpg.pokemon I/art﹕ Debugger is no longer active

1 个答案:

答案 0 :(得分:1)

您正在使用主题android:theme="@android:style/Theme.NoTitleBar.Fullscreen",错误日志会告诉您

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

可能是因为您尝试在活动中使用支持库(import android.support.v7.app.ActionBarActivity;

因此,您的解决方案是遵守日志并使用符合Theme.AppCompat的主题或使用不依赖于支持库的活动。在第一种情况下,您需要将style.xml文件中的父主题设置为Theme.AppCompat