Interface compatibility issues between different API versions

I am working on an application that uses a navigation box (which I created from an Android Studio activity template) that uses fragmentsinternally. Navigation box nested in mine MainActivity. I also included a menu in the toolbar, which has two more options; Filter and settings (settings created from the AS template too). I ran into problems testing the application between API 19 and 24.

My LoginActivity uses the attribute drawableLeftalong with drawableTint(which, as I know, only works for API23 and higher). How can I get the drawableLeft icon to display in white in older versions? LoginActivity

, Toolbar . API 24 ( Nexus 5X), Toolbar , API 19, Toolbar , . , Material Design, API 23+ ( ), ?

Mainactivity

app_bar_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.michael.whatsupldn.MainActivity">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="centerCrop"
        android:src="@drawable/london_skyline_dark"
        android:layout_alignParentTop="true"
        android:id="@+id/imageView"
        android:contentDescription="@string/london_skyline"/>

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            android:elevation="4dp"
            android:fitsSystemWindows="true"
            app:popupTheme="@style/AppTheme.PopupOverlay"/>

    </android.support.design.widget.AppBarLayout>

    <include layout="@layout/content_main" />

</android.support.design.widget.CoordinatorLayout>

!

P.S. - , .

Toolbar FilterActivity... FiltersActivity

UPDATE

fitsSystemWindows AppBarLayout CoordinatorLayout , . , API 24.

MainActivity after EDIT

+4
4

№ 1 ​​ .

# 2 , styles. AppTheme , <item name="android:windowTranslucentStatus">true</item>, Status bar, , Action Bar / Toolbar .

0

, .....

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="24dp"
    android:height="24dp"
    android:viewportWidth="24.0"
    android:viewportHeight="24.0">
<path
    android:fillColor="@color/colorWhite"
    android:pathData="M12,17c1.1,0 2,-0.9 2,-2s-0.9,-2 -2,-2 -2,0.9 -2,2 
    0.9,2 2,2zM18,8h-1L17,6c0,-2.76 -2.24,-5 -5,-5S7,3.24 7,6v2L6,8c-1.1,0 
    -2,0.9 -2,2v10c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2L20,10c0,-1.1 -0.9,-2 
    -2,-2zM8.9,6c0,-1.71 1.39,-3.1 3.1,-3.1s3.1,1.39 
     3.1,3.1v2L8.9,8L8.9,6zM18,20L6,20L6,10h12v10z"/>
 </vector>

     android:fillColor="@color/colorWhite"

.....

     android:fillColor="#FFFFFF"

, . enter image description here

+2

drawableLeft ?

DrawableCompat:

Drawable drawable = getResources().getDrawable(R.drawable.some_drawable);
drawable = DrawableCompat.wrap(drawable);
DrawableCompat.setTint(drawable.mutate(), getResources().getColor(android.R.color.white));

( )?

android:fitsSystemWindows="true" Toolbar .

+1

, :

// 0=left, 1=top , 2=right , 3=bottom
    editText.getCompoundDrawables[0].mutate().setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP); 
+1

Source: https://habr.com/ru/post/1681861/


All Articles