Android AppCompat 模块 Activity 未使用清单上定义的样式
Android AppCompat Module Activity not using the style defined on the Manifest
我有一个 Android 项目,其中包含提供特定功能的模块。
现在,如果我在从 AppCompat 扩展的模块上定义一个 Activity 并尝试在主应用程序上使用它,工具栏不会采用清单上定义的样式(activity 未使用主应用主题)。
到目前为止我已经尝试过:
在主应用程序清单上定义主题标签。
android:theme="@style/AppTheme"
在主应用程序清单上定义 activity 并在那里设置主题。
<activity android:name=".mymodule.views.MyActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize"
android:screenOrientation="nosensor"
android:theme="@style/AppTheme">
</activity>
在模块清单上定义 activity 并在那里设置主题。
<activity android:name=".views.MyActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize"
android:screenOrientation="nosensor"
android:theme="@style/AppTheme">
</activity>
我的 styles.xml 文件如下所示(对于主应用程序和模块):
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark_color</item>
<item name="colorAccent">@color/accent</item>
...
</style>
工具栏 XML 如下:
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="@style/AppTheme"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:theme="@style/AppTheme"
/>
我已经尝试 android:theme 和 app:theme 来专门设置工具栏的样式,但仍然没有任何变化。
有什么想法吗?
谢谢!
好的,所以我找到了解决方案。
我不得不将工具栏包裹在 AppBarLayout 周围,它起作用了。我的猜测是,这是 AppCompat 的一个问题...但无论如何,这就是它对我有用的方式!
我有一个 Android 项目,其中包含提供特定功能的模块。
现在,如果我在从 AppCompat 扩展的模块上定义一个 Activity 并尝试在主应用程序上使用它,工具栏不会采用清单上定义的样式(activity 未使用主应用主题)。
到目前为止我已经尝试过:
在主应用程序清单上定义主题标签。
android:theme="@style/AppTheme"
在主应用程序清单上定义 activity 并在那里设置主题。
<activity android:name=".mymodule.views.MyActivity" android:configChanges="keyboardHidden|orientation|screenSize" android:windowSoftInputMode="adjustResize" android:screenOrientation="nosensor" android:theme="@style/AppTheme"> </activity>
在模块清单上定义 activity 并在那里设置主题。
<activity android:name=".views.MyActivity" android:configChanges="keyboardHidden|orientation|screenSize" android:windowSoftInputMode="adjustResize" android:screenOrientation="nosensor" android:theme="@style/AppTheme"> </activity>
我的 styles.xml 文件如下所示(对于主应用程序和模块):
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark_color</item>
<item name="colorAccent">@color/accent</item>
...
</style>
工具栏 XML 如下:
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="@style/AppTheme"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:theme="@style/AppTheme"
/>
我已经尝试 android:theme 和 app:theme 来专门设置工具栏的样式,但仍然没有任何变化。
有什么想法吗?
谢谢!
好的,所以我找到了解决方案。
我不得不将工具栏包裹在 AppBarLayout 周围,它起作用了。我的猜测是,这是 AppCompat 的一个问题...但无论如何,这就是它对我有用的方式!