到目前为止我正在处理的应用程序工作正常,直到我添加了几个新活动并尝试对主题应用了一些更改。
以下是我的styles.xml文件。我查看了其他结果,并在AppTheme中添加了一个父项,因为我之前收到的有关AppCompat的错误。我还制作了NoThectionBar的AppTheme父母。我注意到的一件事是,当我将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)
答案 0 :(得分:0)
更改您的清单文件:
<activity android:name=".UserManagement.RegisterUserActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.AppBarOverlay">
</activity>
到此:
<activity android:name=".UserManagement.RegisterUserActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme">
</activity>
我认为您的 RegisterUserActivity 问题将会解决......
MainActivty的更新 Chnage style.xml
<!-- 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>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
答案 1 :(得分:0)
将此代码放入style.xml
nested exception is org.springframework.data.mapping.PropertyReferenceException: No property unit found for type Phase!
并且不要添加父=&#34; AppTheme&#34;在上面的代码中。
答案 2 :(得分:0)
它适用于代码的以下更改:
<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>