主题更新后应用程序崩溃

克里希纳·阿迪卡里

到目前为止,我正在开发的应用程序运行良好,直到我添加了一些新活动并尝试对主题进行了一些更改。

以下是我的styles.xml 文件。我查看了其他结果,并在 AppTheme 中添加了一个父项,因为我之前收到了关于 AppCompat 的错误。我还让 AppTheme 成为 NoActionBar 的父级。我注意到的一件事是,当我应用 AppBarOverlay 来注册用户活动时它会崩溃,而当我应用其他时它不会。无论如何,主要活动正在崩溃。

<resources>

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

<style name="AppTheme.NoActionBar" parent ="AppTheme">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>

以下是 Android 清单文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ati.activate">
<application
    android:allowBackup="true"
    android:icon="@drawable/footprintblue"
    android:label="@string/app_name"
    android:roundIcon="@drawable/footprintgreen"
    android:theme="@style/AppTheme"
    android:supportsRtl="true">

    <activity android:name=".UserManagement.LoginActivity"
        android:theme="@style/AppTheme.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity android:name=".UserManagement.RegisterUserActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.AppBarOverlay">
    </activity>

    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">
    </activity>

 </application>
</manifest>

我已将 AppTheme 应用于 android,然后将所需的主题覆盖到其他活动。注意:登录屏幕工作并使用 AppTheme.NoTitleBar,注册用户在没有 AppBarOverLay 主题的情况下工作,但在使用此主题时崩溃。

这是我的 activity_main.xml 文件

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.ati.activate.MainActivity">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingTop="@dimen/appbar_padding_top"
    android:theme="@style/AppTheme.AppBarOverlay">

    <!--android:paddingTop="@dimen/appbar_padding_top"-->

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        app:popupTheme="@style/AppTheme.PopupOverlay"
        app:layout_scrollFlags="scroll|enterAlways">
    </android.support.v7.widget.Toolbar>

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/login_background" />

</android.support.design.widget.AppBarLayout>

<android.support.v4.view.ViewPager
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

这是我的 MainActivity.Java 文件的片段:

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;

import android.support.v4.view.ViewPager;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;

import com.ati.activate.Fragments.SettingsFragment.AppSettingsFragment;
import com.ati.activate.Fragments.SettingsFragment.ProfileSettingsFragment;

public class MainActivity extends AppCompatActivity{
private AppPagerAdapter mAppPagerAdapter;
private ViewPager mViewPager;

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

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    createMenu();
}

我已经尝试了互联网上讨论的所有解决方案,但仍然没有找到任何解决方案。有人可以帮忙吗?提前谢谢你。

以下是使用 AppTheme.AppBarOverlay 打开注册用户活动时的错误:

    12-08 04:55:08.217 17843-17850/? E/zygote: Failed writing handshake bytes (-1 
    of 14): Broken pipe
    12-08 04:55:16.704 17843-17986/com.ati.activate E/StudioProfiler: JVMTI 
    error: 15(JVMTI_ERROR_THREAD_NOT_ALIVE) 
    12-08 04:55:16.706 17843-17986/com.ati.activate E/StudioProfiler: JVMTI 
    error: 15(JVMTI_ERROR_THREAD_NOT_ALIVE) 
    12-08 04:55:16.818 17843-17843/com.ati.activate E/AndroidRuntime: FATAL 
    EXCEPTION: main
                                                                  Process: 
    com.ati.activate, PID: 17843

    java.lang.RuntimeException: Unable to start activity 

ComponentInfo{com.ati.activate/com.ati.activate.UserManagement.RegisterUserActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

                                                                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
                                                                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
                                                                      at android.app.ActivityThread.-wrap11(Unknown Source:0)
                                                                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
                                                                      at android.os.Handler.dispatchMessage(Handler.java:105)
                                                                      at android.os.Looper.loop(Looper.java:164)
                                                                      at android.app.ActivityThread.main(ActivityThread.java:6541)
                                                                      at java.lang.reflect.Method.invoke(Native Method)
                                                                      at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
                                                                   Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
                                                                      at android.support.v7.app.AppCompatDelegateImplV9.createSubDecor(AppCompatDelegateImplV9.java:359)
                                                                      at android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:328)
                                                                      at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:289)
                                                                      at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
                                                                      at com.ati.activate.UserManagement.RegisterUserActivity.onCreate(RegisterUserActivity.java:13)
                                                                      at android.app.Activity.performCreate(Activity.java:6975)
                                                                      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
                                                                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
                                                                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892) 
                                                                      at android.app.ActivityThread.-wrap11(Unknown Source:0) 
                                                                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593) 
                                                                      at android.os.Handler.dispatchMessage(Handler.java:105) 
                                                                      at android.os.Looper.loop(Looper.java:164) 
                                                                      at android.app.ActivityThread.main(ActivityThread.java:6541) 
                                                                      at java.lang.reflect.Method.invoke(Native Method) 
                                                                      at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
                                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 

这是打开主活动时的错误:

12-08 04:59:50.431 21418-21586/com.ati.activate E/StudioProfiler: JVMTI 

error: 15(JVMTI_ERROR_THREAD_NOT_ALIVE) 
12-08 04:59:50.432 21418-21586/com.ati.activate E/StudioProfiler: JVMTI error: 15(JVMTI_ERROR_THREAD_NOT_ALIVE) 
12-08 04:59:50.518 21418-21418/com.ati.activate E/AndroidRuntime: FATAL EXCEPTION: main
                                                                  Process: com.ati.activate, PID: 21418
                                                                  java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ati.activate/com.ati.activate.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
                                                                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
                                                                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
                                                                      at android.app.ActivityThread.-wrap11(Unknown Source:0)
                                                                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
                                                                      at android.os.Handler.dispatchMessage(Handler.java:105)
                                                                      at android.os.Looper.loop(Looper.java:164)
                                                                      at android.app.ActivityThread.main(ActivityThread.java:6541)
                                                                      at java.lang.reflect.Method.invoke(Native Method)
                                                                      at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
                                                                   Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
                                                                      at android.support.v7.app.AppCompatDelegateImplV9.createSubDecor(AppCompatDelegateImplV9.java:359)
                                                                      at android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:328)
                                                                      at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:289)
                                                                      at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
                                                                      at com.ati.activate.MainActivity.onCreate(MainActivity.java:26)
                                                                      at android.app.Activity.performCreate(Activity.java:6975)
                                                                      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
                                                                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
                                                                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892) 
                                                                      at android.app.ActivityThread.-wrap11(Unknown Source:0) 
                                                                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593) 
                                                                      at android.os.Handler.dispatchMessage(Handler.java:105) 
                                                                      at android.os.Looper.loop(Looper.java:164) 
                                                                      at android.app.ActivityThread.main(ActivityThread.java:6541) 
                                                                      at java.lang.reflect.Method.invoke(Native Method) 
                                                                      at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
                                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 
克里希纳·阿迪卡里

它适用于对代码的以下更改:

<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>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowFullscreen">true</item>
</style>

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

firebase 更新了重大更改后,我的应用程序崩溃了

来自分类Dev

主题更改后应用程序崩溃(显然是由片段引起的)

来自分类Dev

iOS应用程序(使用核心数据)在更新后崩溃,但仅应用程序商店版本崩溃

来自分类Dev

Proguard后Android应用程序崩溃

来自分类Dev

首次启动后应用程序崩溃

来自分类Dev

onResume后应用程序崩溃

来自分类Dev

显示通知后崩溃的应用程序

来自分类Dev

出现UIImagePickerController后,应用程序崩溃

来自分类Dev

首次启动后应用程序崩溃

来自分类Dev

拍照后应用程序崩溃

来自分类Dev

单击按钮后,应用程序崩溃

来自分类Dev

添加editText后应用程序崩溃

来自分类Dev

更新时列出崩溃应用程序

来自分类Dev

在样式下更改主题时,应用程序崩溃

来自分类Dev

openURL() 中的双主题标签使应用程序崩溃

来自分类Dev

异常后地图崩溃导致应用程序崩溃

来自分类Dev

更新到Android 3.6工作室后,在运行时应用程序崩溃

来自分类Dev

“通过heroku-postgresql更新数据库”后,应用程序崩溃

来自分类Dev

输入密码后单击按钮后应用程序崩溃

来自分类Dev

应用程序更新后的Coredata

来自分类Dev

如何更新我的项目以创建多主题应用程序

来自分类Dev

启用Proguard后,Android应用程序崩溃

来自分类Dev

声明RealmSwift类后,我的应用程序崩溃

来自分类Dev

从.NET 3.5移至.NET 4.0后,应用程序崩溃

来自分类Dev

崩溃后如何重新启动Qt应用程序?

来自分类Dev

升级到播放2.2后,应用程序崩溃

来自分类Dev

添加MediaRouteButton后,我的应用程序崩溃

来自分类Dev

创建搜索界面后,应用程序崩溃

来自分类Dev

超时后URL连接崩溃的应用程序

Related 相关文章

热门标签

归档