【发布时间】:2019-01-05 04:12:45
【问题描述】:
我的应用程序存在问题,尤其是工具栏和状态栏行为不正确。我希望我的工具栏和状态栏是相同的颜色以无缝融合。另外,我希望所有活动的标签上都显示活动标题。对于某些活动,这很好用。例如,主要活动:
但是,除 Main Activity 之外的所有 Activity 都拒绝显示 Label,并且只有 Main Activity 和代表 Activity 显示正确的颜色配置。例如,代表工具栏具有正确的颜色组合,但没有标签。
其他活动都没有正确的颜色组合或标签,如单一代表活动
这是我的 Android 清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.gabe.politicianspulse">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
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=".VoterInformation"
android:label="@string/title_activity_voter_information"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".Representatives"
android:label="Representatives"
android:theme="@style/AppTheme.NoActionBar" />
<activity android:name=".SingleRepresentative"
android:label="@string/title_activity_single_representative"
android:theme="@style/AppTheme.NoActionBar"
/>
<activity android:name=".Elections"
android:label="@string/elections"
android:theme="@style/AppTheme.NoActionBar"
/>
<activity android:name=".SingleElection"
tools:ignore="ExtraText"
android:label="@string/elections"
android:theme="@style/AppTheme.NoActionBar"
>
</activity>
</application>
工具栏代码:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimaryDark"
android:id="@+id/toolbar"
app:titleTextColor="#ffffff">
</android.support.v7.widget.Toolbar>
colors.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#ffffff</color>
<color name="colorPrimaryDark">#2F3C4B</color>
<color name="colorAccent">#CC4848</color>
</resources>
我可以根据要求从任何活动交付任何 Java 或 XML 代码。谢谢您的帮助! -加布
【问题讨论】:
-
您的活动是否扩展
AppCompatAcitivity?您的活动代码中是否有任何工具栏设置? -
是的,我的课程扩展了 AppCompatActivity。为了设置工具栏,我在布局文件中编写了一些 xml 代码。
标签: xml android-layout label toolbar android-statusbar