显示键盘的控制位置
Control position of displayed keyboard
作为我在 android 中的新手,我正在编写一个应用程序,在我的布局文件中,我在屏幕底部有一个编辑文本和下面的两个按钮,如下所示:
<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>
这是结果:
当用户点击编辑文本时,键盘会越过绿色按钮,而且我的操作栏和屏幕上方的部分也会消失或消失,否则。这是我的问题:我怎样才能拥有如下图所示的状态?
在这张图片中,发送按钮和编辑文本都在一行中,对我来说是两行。谢谢大家。
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:windowSoftInputMode="adjustPan"
>
将此添加到您的清单文件中。
我认为您需要在 AndroidManifest.xml
文件中添加这一行:
android:windowSoftInputMode="stateVisible|adjustResize">
在 <activity>
部分。
之后您的清单 xml
文件将如下所示
?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>
打开键盘后您的视图将如下所示
请同时检查:How to add a bottom menu to Android activity
如果您有任何问题,请随时提出。
希望对您有所帮助
作为我在 android 中的新手,我正在编写一个应用程序,在我的布局文件中,我在屏幕底部有一个编辑文本和下面的两个按钮,如下所示:
<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>
这是结果:
当用户点击编辑文本时,键盘会越过绿色按钮,而且我的操作栏和屏幕上方的部分也会消失或消失,否则。这是我的问题:我怎样才能拥有如下图所示的状态?
在这张图片中,发送按钮和编辑文本都在一行中,对我来说是两行。谢谢大家。
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:windowSoftInputMode="adjustPan"
>
将此添加到您的清单文件中。
我认为您需要在 AndroidManifest.xml
文件中添加这一行:
android:windowSoftInputMode="stateVisible|adjustResize">
在 <activity>
部分。
之后您的清单 xml
文件将如下所示
?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>
打开键盘后您的视图将如下所示
请同时检查:How to add a bottom menu to Android activity
如果您有任何问题,请随时提出。
希望对您有所帮助