简体   繁体   中英

Toolbar not visible on Android 4.X devices

It is so long that I can not solve this problem.

I have seen many similar topics but none of them have solved my problem:

This is my "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>

This is my "AndroidManifest.xml":

<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>

This is "toolbar.xml":

<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"/>

This is my "activiy_main.xml"

<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 -->

And this is a part of my "MainActivity.java"

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);

}

How can I make the Toolbar visible in Android 4.x?

Please help me...

Change your theme to something like Theme.AppCompat.Light.NoActionBar or dark and make sure you provide at least the three colors:

<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>

or similar…

Also… Toolbar toolbar = null; is not needed; you can do Toolbar toolbar; and get the same result, with less typing. ;)

Additionally, I'd wrap your toolbar layout in a <merge> tag and add android:layout_alignParentTop="true" to the toolbar, so it properly positions itself.

The "shadow" of your toolbar should be layout_below="@id/toolbar" . You can add an id when you include a layout by doing:

<include
    android:id="@+id/toolbar"
    layout="@layout/layout_toolbar"
    />

This way, the including layout can use the @id.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM