EditText attribute attribute does not work the same for API 19 and 21

I connect screen capture using both 19 and 21 emulators: enter image description here

On the left is Android 19, and on the right is 21. As you can see, the emulator based on API 19 does not take into account the add-on attribute. The same thing happens on the 4.4.x device, so this is not only a problem with the emulator.

This is the .xml code I'm using for this action:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.birsan.cardbox.FolderScreen">

<ImageView
    android:id="@+id/magnifying_glass_icon"
    android:layout_width="20dp"
    android:layout_height="20dp"
    android:layout_alignBottom="@+id/search_button"
    android:layout_alignLeft="@+id/search_folder"
    android:layout_alignStart="@+id/search_folder"
    android:layout_marginBottom="2dp"
    android:layout_marginLeft="9dp"
    android:layout_marginStart="9dp"
    android:contentDescription="magnifying glass"
    android:src="@drawable/ic_menu_search" />

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


<EditText
    android:id="@+id/search_folder"
    android:layout_width="250dp"
    android:layout_height="30dp"
    android:layout_marginLeft="8dp"
    android:layout_marginTop="10dp"
    android:background="@drawable/search_custom_widget"
    android:focusable="true"
    android:hint="Search in folders"
    android:iconifiedByDefault="false"
    android:paddingLeft="40dp"
    android:paddingRight="55dp"
    android:singleLine="true"
    android:textSize="14sp"

    android:textStyle="bold" />

<Button
    android:id="@+id/search_button"
    style="?android:attr/buttonStyleSmall"
    android:layout_width="wrap_content"
    android:layout_height="26dp"
    android:layout_alignBottom="@+id/search_folder"
    android:layout_alignEnd="@+id/search_folder"
    android:layout_alignRight="@+id/search_folder"
    android:layout_marginBottom="2dp"
    android:layout_marginRight="2dp"
    android:background="@color/my_blue"

    android:text="Go"
    android:textColor="#fff"
    android:textSize="10sp" />


<com.name.cardbox.SlidingTabLayout
    android:id="@+id/sliding_tabs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_below="@+id/app_bar"
    android:layout_marginTop="40dp"
    android:background="@color/my_blue" />


<android.support.v4.view.ViewPager
    android:id="@+id/viewpager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/sliding_tabs"
    android:background="#fff">


</android.support.v4.view.ViewPager>

Why the discrepancy? What am I missing and how can I fix it? Thank.

+2
source share
2 answers

This seems to be a bug in API 21 - Issue 77982 .

. .

: 1) Actually, the 21 works fine. Is the 19 that doesn't.

- " api 21 Android". sdk 21, sdk 21, apis.

2) searchView.setPadding(40, 0, 55, 0);

, , . dp

int paddingLeft = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 40, getResources().getDisplayMetrics());
        int paddingRight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 55, getResources().getDisplayMetrics());
        int paddingTop = editText.getPaddingTop();
        int paddingBottom = editText.getPaddingBottom();
        editText.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);
+5

android:paddingStart android:paddingLeft, . .

0

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


All Articles