【问题标题】:Small change in android manifests is causing app to crashandroid 清单中的微小变化导致应用程序崩溃
【发布时间】:2016-10-18 04:04:20
【问题描述】:

非常简单,我正在更改我的 android 清单以删除标题栏。在 styles.xml 文件中,我更改了应用程序样式父级,并在 android 清单中相应地更改了 android:theme。但是现在,当我在我的 android 上进行测试时,它只会进入白屏。

我的样式.xml:

<resources>

<!-- Base application theme. -->
<style name="AppTheme"
    parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

我的 android_manifests:

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

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen">
    <activity android:name=".MainActivity"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".ColorMatch2"
        android:screenOrientation="portrait">
    </activity>
    <activity android:name=".LoseScreen"
        android:screenOrientation="portrait">
    </activity>
</application>

</manifest>

我的 MainActivity.java,它可能无关紧要,但以防万一它是罪魁祸首:

package com.example.ali.colormatch2;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;


public class MainActivity extends AppCompatActivity {

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

public void onSplashPageClick(View view){
    Intent intent = new Intent(MainActivity.this, ColorMatch2.class);
    startActivity(intent);
}

public void onQuitClick(View view){
    finish();
}
}

对应activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#005825"
tools:context="com.example.ali.colormatch2.MainActivity"
android:onClick="onSplashPageClick"

android:baselineAligned="false">

<!--<Button
    android:text="Button"
    android:layout_width="159dp"
    android:layout_height="100dp"
    android:id="@+id/button5"
    android:onClick="sendMessage" />
    -->


<Button
    android:layout_width="35dp"
    android:layout_height="35dp"
    android:id="@+id/button"
    android:background="@android:drawable/btn_dialog"
    android:onClick="onQuitClick"
    android:layout_marginTop="16dp"
    android:layout_marginLeft="24dp"
    android:layout_marginStart="24dp"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />

<TextView
    android:text="Click anywhere to play"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/textView5"
    android:textSize="30dp"
    android:textColor="#000000"
    android:layout_marginBottom="171dp"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:fontFamily="sans-serif-thin"
    android:text="Color Match"
    android:gravity="center"
    android:textColor="#440027"
    android:textSize="75dp"
    android:id="@+id/textView"
    android:layout_marginBottom="12dp"
    android:layout_above="@+id/textView5"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />


</RelativeLayout>

另外应该注意我也试过 android:theme="@android:style/Theme.Light.NoTitleBar"> 在 android 清单中,但这似乎也不起作用。谢谢

编辑----

Logcat 输出:

3:21:37 PM Gradle sync started
3:22:01 PM Gradle sync completed
3:22:02 PM Executing tasks: [:app:generateDebugSources, :app:mockableAndroidJar, :app:prepareDebugUnitTestDependencies, :app:generateDebugAndroidTestSources]
3:22:06 PM Gradle build finished in 5s 131ms
3:26:53 PM Executing tasks: [:app:assembleDebug]
3:26:58 PM Gradle build finished in 5s 281ms
3:37:53 PM Executing tasks: [:app:assembleDebug]
3:37:55 PM Gradle build finished in 2s 165ms
3:38:02 PM Performing full build and install:
       On devices with API level below 21, a full build is required if the app is not running.
       (Dont show again)
3:40:37 PM Executing tasks: [:app:assembleDebug]
3:40:40 PM Gradle build finished in 2s 187ms
3:40:47 PM Performing full build and install:
       On devices with API level below 21, a full build is required if the app is not running.
       (Dont show again)
11:15:21 PM Executing tasks: [:app:assembleDebug]
11:15:46 PM Gradle build finished in 24s 689ms
11:18:22 PM Executing tasks: [:app:assembleDebug]
11:18:27 PM Gradle build finished in 5s 487ms
11:18:34 PM Performing full build and install:
        On devices with API level below 21, a full build is required if the app is not running.
        (Dont show again)
11:19:52 PM Executing tasks: [:app:assembleDebug]
11:19:53 PM Gradle build finished in 1s 893ms
11:20:00 PM Performing full build and install:
        On devices with API level below 21, a full build is required if the app is not running.
        (Dont show again)
11:48:01 PM Executing tasks: [:app:assembleDebug]
11:48:05 PM Gradle build finished in 4s 209ms
11:48:13 PM Performing full build and install:
        On devices with API level below 21, a full build is required if the app is not running.
        (Dont show again)
11:48:52 PM Executing tasks: [:app:assembleDebug]
11:48:53 PM Gradle build finished in 1s 96ms
11:48:55 PM Performing full build and install:
        On devices with API level below 21, a full build is required if the app is not running.
        (Dont show again)
11:49:56 PM Executing tasks: [:app:assembleDebug]
11:49:58 PM Gradle build finished in 1s 735ms
11:50:05 PM Performing full build and install:
        On devices with API level below 21, a full build is required if the app is not running.
        (Dont show again)
11:52:14 PM Executing tasks: [:app:assembleDebug]
11:52:17 PM Gradle build finished in 3s 8ms
11:52:24 PM Performing full build and install:
        On devices with API level below 21, a full build is required if the app is not running.
        (Dont show again)
11:57:56 PM Executing tasks: [:app:assembleDebug]
11:58:02 PM Gradle build finished in 5s 654ms
11:58:08 PM Performing full build and install:
        On devices with API level below 21, a full build is required if the app is not running.
        (Dont show again)
11:59:12 PM Executing tasks: [:app:assembleDebug]
11:59:14 PM Gradle build finished in 1s 664ms
11:59:21 PM Performing full build and install:
        On devices with API level below 21, a full build is required if the app is not running.
        (Dont show again)
12:01:51 AM Executing tasks: [:app:assembleDebug]
12:01:53 AM Gradle build finished in 1s 917ms
12:01:59 AM Performing full build and install:
        On devices with API level below 21, a full build is required if the app is not running.
        (Dont show again)
12:13:12 AM Executing tasks: [:app:assembleDebug]
12:13:17 AM Gradle build finished in 5s 159ms
12:13:25 AM Performing full build and install:
        On devices with API level below 21, a full build is required if the app is not running.
        (Dont show again)
12:22:27 AM Executing tasks: [:app:assembleDebug]
12:22:32 AM Gradle build finished in 4s 708ms
12:22:39 AM Performing full build and install:
        On devices with API level below 21, a full build is required if the app is not running.
        (Dont show again)
12:23:38 AM Executing tasks: [:app:assembleDebug]
12:23:41 AM Gradle build finished in 2s 643ms
12:23:49 AM Performing full build and install:
        On devices with API level below 21, a full build is required if the app is not running.
        (Dont show again)
12:24:02 AM Executing tasks: [:app:assembleDebug]
12:24:05 AM Gradle build finished in 2s 215ms
12:24:23 AM Performing full build and install:
        On devices with API level below 21, a full build is required if the app is not running.
        (Dont show again)
12:24:23 AM Can't bind to local 8600 for debugger

【问题讨论】:

  • 请发布您的 logcat 输出。另外,您在哪里使用了 My styles.xml 主题?

标签: java android xml android-manifest android-styles


【解决方案1】:

更改此android:theme="@android:style/Theme.Light.NoTitleBar.Fullscr‌​een" 转入android:theme="@style/AppTheme"

【讨论】:

  • 成功了!谢谢!实际上,我之前用 android:theme ="@android:style/AppTheme" 尝试过类似的东西,但很快就放弃了。我只是语法错误。你是最棒的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-05-08
  • 2013-12-02
  • 2014-09-09
  • 1970-01-01
  • 1970-01-01
  • 2022-10-05
  • 1970-01-01
相关资源
最近更新 更多