2

My TextInputLayout with EditText is decreasing when i touch this place.
I have 2 questions, what i should fix if i want this same size EditText, and what i should add for always keyboard on screen.

enter image description here

xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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/linearLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="pl.xd.hello.WeatherActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="6"
        android:orientation="horizontal">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="horizontal">

            <android.support.design.widget.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <EditText
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="Podaj miejscowość" />
            </android.support.design.widget.TextInputLayout>
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="4"
            android:gravity="center"
            android:orientation="horizontal">

            <android.support.design.widget.FloatingActionButton
                android:id="@+id/floatingActionButton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:clickable="true"
                app:backgroundTint="@android:color/holo_red_dark"
                app:fabSize="mini"
                app:srcCompat="@drawable/ic_check_circle_black_24dp" />
        </LinearLayout>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="horizontal">

        <ListView
            android:id="@+id/weatherListView"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </LinearLayout>
</LinearLayout>
philips
  • 111
  • 1
  • 8

1 Answers1

1

for your first question make your EditText like below to fix it with its parent size

<android.support.design.widget.TextInputLayout
 android:layout_width="match_parent"
 android:layout_height="wrap_content">
<EditText
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:hint="Podaj miejscowość" />
</android.support.design.widget.TextInputLayout>

For the second question you should add android:windowSoftInputMode="stateAlwaysVisible" to your activity in the AndroidManifest.xml file like below:

<activity android:name=".MainActivity"
 android:label="@string/app_name"
 android:windowSoftInputMode="stateAlwaysVisible" />

this would open the softkeyboard for your whole app, you can take a look at this post for more info. but if you want to open the keyboard only for this activity or fragment you can add a method to open keyboard manually like below :

public static void showKeyboard(EditText editText) {

    if (editText != null) {
        InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
    }
}
SepJaPro2.4
  • 704
  • 9
  • 19
  • change from match_parent to wrap_content did no help, edit text is still decreasing after touch – philips Jul 17 '17 at 10:25
  • if i change weight, i have just more place, but anyway size is changing – philips Jul 17 '17 at 10:32
  • Whether "weight" is delete, increase or decrease, there is no difference, all the time size changed by touch :( – philips Jul 17 '17 at 10:39
  • srry i haven't noticed that the weights are for the width and not for the height , so try making you `TextInputLayout` `android:layout_height="wrap_content"` see if this solves your problem. – SepJaPro2.4 Jul 17 '17 at 10:48