很长时间以来我无法解决这个问题。
我见过很多类似的话题,但没有一个能解决我的问题:
这是我的" Style.xml":
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="windowActionBarOverlay">false</item>
<item name="windowActionModeOverlay">true</item>
<!-- Customize your theme here. -->
</style>
<style name="ToolbarColoredBackArrow" parent="AppTheme">
<item name="android:textColorSecondary">@color/bianco</item>
</style>
<style name="MyEditTextTheme">
<!-- Usato per il background dell'edittext prima di android kitkat-->
<item name="colorControlNormal">@color/blu_copyworld_premuto</item>
<item name="colorControlActivated">@color/blu_copyworld</item>
<!-- colorControlHighlight use the colorAccent color by default -->
</style>
这是我的&#34; AndroidManifest.xml&#34;:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="copyworld.assistenzamobile" >
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:configChanges="orientation|screenSize"><!-- Per non distruggere e ricreare l'activity quando viene girato lo schermo in orizzontale o in verticale -->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Per supportare anche il dual schermo-->
<uses-library android:required="false" android:name="com.sec.android.app.multiwindow" />
<meta-data android:name="com.sec.android.support.multiwindow" android:value="true" />
<meta-data android:name="com.sec.android.multiwindow.DEFAULT_SIZE_W" android:value="632.0dip" />
<meta-data android:name="com.sec.android.multiwindow.DEFAULT_SIZE_H" android:value="598.0dip" />
<meta-data android:name="com.sec.android.multiwindow.MINIMUM_SIZE_W" android:value="632.0dip" />
<meta-data android:name="com.sec.android.multiwindow.MINIMUM_SIZE_H" android:value="598.0dip" />
</application>
这是&#34; toolbar.xml&#34;:
<android.support.v7.widget.Toolbar
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/blu_copyworld"
android:elevation="7dp"
app:theme="@style/ToolbarColoredBackArrow"
android:fitsSystemWindows="true"/>
这是我的&#34; activiy_main.xml&#34;
<android.support.v4.widget.DrawerLayout
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/drawer_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<RelativeLayout
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<!--Aggiungo la toolbar o action bar custom-->
<include layout="@layout/toolbar"/>
<!-- Questo è il contenitore dove verranno inseriti i fragment tipo "assistenza1", "assistenza2" ecc-->
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:foreground="@drawable/shadow_toolbar"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
<!-- "foreground" serve per avere la shadow sotto la toolbar, per i dispositivi sotto android 5.0-->
<!-- Inserisco la navigation view ossia la barra laterale, includendo l'header ed il body -->
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/nav_body_main"/>
<!-- "itemIconTint" cambiare colore testo navigation -->
<!-- " itemTextColor" cambiare colore icona navigation -->
这是我的&#34; MainActivity.java&#34;
的一部分protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = null;
toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitleTextColor(Color.WHITE); // cambio colore titolo toolbar
setSupportActionBar(toolbar);
}
如何在Android 4.x中显示工具栏?
请帮帮我......
答案 0 :(得分:1)
将您的主题更改为Theme.AppCompat.Light.NoActionBar
或更暗,并确保至少提供三种颜色:
<style name="AppTheme" parent="AppTheme.Base" />
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowBackground">@android:color/white</item>
</style>
或类似......
另外...... Toolbar toolbar = null;
不需要;你可以做Toolbar toolbar;
并获得相同的结果,减少打字。 ;)
此外,我将工具栏布局包装在<merge>
标记中,然后将android:layout_alignParentTop="true"
添加到工具栏中,以便正确定位。
&#34;影子&#34;您的工具栏应为layout_below="@id/toolbar"
。您可以通过执行以下操作添加ID:
<include
android:id="@+id/toolbar"
layout="@layout/layout_toolbar"
/>
这样,包含布局可以使用@id。