我需要一个帮助才能找到适合我项目这一部分的主题,但首先我相信很高兴首先解释活动的结构以找到答案:
在第二次活动中,问题显然开始了......
我首先按照这个网站建立了屏幕:https://www.androidhive.info/2015/09/android-material-design-working-with-tabs/
但是,通过这个网站,他们使用这种风格:
<style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
但是使用这种风格,根据我的需要,结果就是这个错误:
android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class android.support.design.widget.TabLayout
所以,为了找到答案,我发现这个网站在这里:http://geeksmember.blogspot.com.br/2015/10/errorerror-inflating-class.html
谁在样式文件中向我展示了这个解决方案
<style name="AppTheme.Base" parent="android:Theme.Material">
这是一个很好的解决方案,很好,因为在这一刻我可以从其他风格中分离主要风格。好的... buuuuut ...当我启动应用程序时,出现此错误:
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
所以...这是我的问题...因为,当我使用“Theme.AppCompat.Light.DarkActionBar”时,第一个错误又出现了......我仍然坚持这种情况,我找不到一个没有风格的人与我的需求相匹配......
如果有人需要样式文件...(这是除主要活动之外的所有活动的样式文件)
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="AppTheme.Base" />
<style name="AppTheme.Base" parent="***I Need a theme here, i know, this is my question*** :)">
<item name="android:colorPrimary">#212121</item>
<item name="android:colorPrimaryDark">#000000</item>
<item name="android:colorAccent">#303030</item>
</style>
<style name="MyCustomTabLayout" parent="Widget.Design.TabLayout">
<item name="tabIndicatorColor">#80CBC4</item>
</style>
</resources>
你有两个选择:
为此,您需要创建“操作栏主题”和“无操作栏主题”:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#212121</item>
<item name="colorPrimaryDark">#000000</item>
<item name="colorAccent">#303030</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
然后,在您的清单中,您将第一个主题分配给您的应用,将第二个主题分配给您不想要操作栏的任何屏幕:
<application
...
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:theme="@style/AppTheme.NoActionBar">
...
</activity>
</application>
因此,默认情况下,所有屏幕都会有一个操作栏,但是任何不应该有操作栏的活动都可以通过为该单个活动指定AppTheme.NoActionBar
来设置。
对于这种方法,您可以创建您的应用主题,以便没有操作栏:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#212121</item>
<item name="colorPrimaryDark">#000000</item>
<item name="colorAccent">#303030</item>
</style>
然后,在任何应该有操作栏的活动中,您需要在活动的布局中添加Toolbar
:
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
在您的活动的onCreate()
方法中,在设置内容视图后,您将告诉系统将此工具栏用作操作栏:
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);