选项卡干扰应用程序和活动主题
我们正在开发一个具有多个不同选项卡的 Android 应用程序。我们一直在尝试将主题应用于整个应用程序,并且我们还尝试将主题应用于特定活动。两者都没有任何效果。
我有这个样式文件:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<style name="recapmain">
<item name="android:buttonStyle">@style/recapButton</item>
<item name="android:textViewStyle">@style/recapText</item>
</style>
<style name="recapButton" parent="android:style/Widget.Button">
<item name="android:textSize">30sp</item>
<item name="android:background">#FF0000</item>
</style>
<style name="recapText">
<item name="android:textSize">30dip</item>
<item name="android:textColor">#FFFFFF</item>
</style>
</resources>
清单文件中的应用程序标记如下所示:
<application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@style/recapmain">
<activity android:name="appname"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
这不起作用。该应用程序根本不响应主题。如果我设置一个特定的视图来使用其中一种样式,它就可以完美地工作。因此,我可以在活动的 xml 文件中执行此操作:
<Button
android:id="@+id/OverviewButtonYears"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/years"
android:onClick="years"
style="@style/recapButton"
/>
这将适当地设置按钮的样式。
我们还尝试将主题应用到特定的活动标签,但没有结果。
现在,真正起作用的是从应用程序标记中删除意图过滤器标记,并将其放入活动标记中,如下所示:
<activity android:name=".PolicyTab" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
仅启动特定活动,并且它确实具有适当的活动主题。
那么我的问题是,为什么?我们猜测它与选项卡有关,因为仅启动一个活动即可启用该主题。我们需要做什么才能让它与选项卡一起工作?
We're developing an android application that has several different tabs. We've been trying to apply a theme to entire application, and we've also tried applying a theme to specific activities. Neither has any effect.
I have this style-file:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<style name="recapmain">
<item name="android:buttonStyle">@style/recapButton</item>
<item name="android:textViewStyle">@style/recapText</item>
</style>
<style name="recapButton" parent="android:style/Widget.Button">
<item name="android:textSize">30sp</item>
<item name="android:background">#FF0000</item>
</style>
<style name="recapText">
<item name="android:textSize">30dip</item>
<item name="android:textColor">#FFFFFF</item>
</style>
</resources>
The application tag in the manifest file looks like this:
<application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@style/recapmain">
<activity android:name="appname"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
This doesn't work. The application simply does not react to the theme. If I set a specific view to use one of the styles, it's works perfectly. So, I can do this in the xml file for an activity:
<Button
android:id="@+id/OverviewButtonYears"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/years"
android:onClick="years"
style="@style/recapButton"
/>
That will style the button appropriately.
we've also tried applying the theme to a specific activity tag, with no result.
Now, what does work, is removing the intent-filter-tag from the application tag, and putting it in an activity tag, like this:
<activity android:name=".PolicyTab" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
That starts the specific activity only, and it does have the appropriate theme.
My question then, is, why? We've gussed that it has something to do with the tabs, since starting only one activity enables the theme. What do we have to do to get it to work with tabs?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您希望主应用程序主题为具有自定义控件样式的 android:theme="@android:style/Theme.NoTitleBar",那么您应该根据您的喜好扩展该主题:
此行将采用将父主题的样式放入
recapmain
中,您可以在其中编写自己的首选项(就像您已经对buttonStyle
和textViewStyle
所做的那样)。在您的
androidManifest.xml
中,您将应用程序主题设置为您的自定义样式:更新
您的 styles.xml 应包含:
If you wany your main application theme to be
android:theme="@android:style/Theme.NoTitleBar"
with customized control styles, then you should extend that theme with your preferences:This line will adopt the styles of the parent theme into
recapmain
, and inside you can write your own preferences (as you already have forbuttonStyle
andtextViewStyle
).Inside your
androidManifest.xml
you set the application theme to your custom style:Update
Your styles.xml should contain: