Beppe
Beppe

Reputation: 201

Control position of displayed keyboard

As I new in android, I'm writing an app that in my layout file, i have an Edit Text and two buttons below of that in bottom of screen like this:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:layout_alignParentBottom="true"
    android:orientation="vertical"
    android:layout_gravity="bottom">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_weight="1"
        android:orientation="horizontal">
        <EditText
            android:id="@+id/composeMessageBody"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:background="@android:color/white"
            android:hint="@string/message_hint"
            android:textColor="@android:color/black"
            android:textSize="18dp" />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_weight="1"
        android:orientation="horizontal">
        <Button
            android:id="@+id/Button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="5dp"
            android:layout_weight="1"
            android:background="@drawable/button_style_left" />
        <Button
            android:id="@+id/Button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="5dp"
            android:layout_weight="1"
            android:background="@drawable/button_style_right" />
    </LinearLayout>

and this is the result:

and when user tap to edit text, the keyboard came over the green buttons, and also my action bar and above part of screen dissappear or gone or else. And this is my question : How can I have the state like the below picture ?

in this picture the send button and edit text are in One row both, and for me in two rows. thank you guys.

Upvotes: 0

Views: 63

Answers (2)

piotrek1543
piotrek1543

Reputation: 19361

I think you need to your AndroidManifest.xml file add this line:

  android:windowSoftInputMode="stateVisible|adjustResize">

at <activity> section.

After that your manifest xml file would look like this

 ?xml version="1.0" encoding="utf-8"?>
<manifest package="com.example.piotr.myapplication"
          xmlns:android="http://schemas.android.com/apk/res/android">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".MainActivity"
            android:windowSoftInputMode="stateVisible|adjustResize">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>

                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>
</manifest>

and your View afet opening keyboard would be look like this

Please check also this: How to add a bottom menu to Android activity

If you would have any question please free to ask.

Hope it help

Upvotes: 1

M.ArslanKhan
M.ArslanKhan

Reputation: 3918

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

Add this in your Manifest file.

Upvotes: 0

Related Questions