简体   繁体   English

工具栏在Android 4.X设备上不可见

[英]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": 这是我的“ 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": 这是我的“ 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": 这是“ 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" 这是我的“ 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" 这是我的“ 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? 如何使工具栏在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: 将您的主题更改为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>

or similar… 或类似...

Also… Toolbar toolbar = null; 另外… Toolbar toolbar = null; is not needed; 不需要; you can do Toolbar toolbar; 你可以做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. 此外,我会将您的工具栏布局包装在<merge>标记中,并将android:layout_alignParentTop="true"到工具栏,以使其正确定位。

The "shadow" of your toolbar should be layout_below="@id/toolbar" . 工具栏的“阴影”应为layout_below="@id/toolbar" You can add an id when you include a layout by doing: 您可以在添加布局时添加ID,方法是:

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

This way, the including layout can use the @id. 这样,包含布局可以使用@id。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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