Rod*_*una 4 android android-layout
这是我的问题,我有一个非常简单的布局,显示2个EditText,一个用于标题,另一个用于描述。这是xml文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<EditText
android:layout_width="match_parent"
android:layout_height="63dp"
android:id="@+id/title_field"
android:background="#ffffffff"
android:hint="@string/titleFieldHint"
android:padding="20dp"
android:textSize="8.5pt"
android:maxLines="1"/>
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray"/>
<EditText
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/description_field"
android:hint="@string/descriptionHint"
android:gravity="top"
android:padding="20dp"
android:scrollbars="vertical"
android:textSize="8.5pt"
android:background="#ffffff"
android:inputType="textMultiLine"
android:textIsSelectable="true"
android:focusableInTouchMode="true" android:layout_weight="1"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
当我使用此布局启动活动时,键盘显示聚焦的title_field,因此我可以编写并单击另一个字段(当键盘仍处于打开状态)并编写说明。但是,如果我隐藏键盘,除非单击title_field,否则它将不会再次显示(键盘),因此description_field不响应,此外title_field支持开箱即用的选择(包括上下文操作栏),而description_field不会让我甚至选择。
我才刚刚开始android开发,我缺少什么吗?
如果您想在特定活动(如搜索活动)开始时使用键盘,请在清单中使用此代码-
注意-用户登陆活动后,它将弹出键盘...
<application ... >
<activity
android:windowSoftInputMode="stateVisible" ... >
...
</activity>
...
Run Code Online (Sandbox Code Playgroud)
你也可以用你的java文件来做。使用Java,您可以更好地控制键盘外观。这是它的代码-
public void showSoftKeyboard(View view) {
if (view.requestFocus()) {
InputMethodManager imm = (InputMethodManager)
getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
}
}
Run Code Online (Sandbox Code Playgroud)
只需调用showSoftKeyboard()方法即可弹出键盘!
希望我能帮助你!干杯!
小智 2
取出android:textIsSelectable="true"。
或者
编辑:
如果您需要能够保留文本以用作新编辑文本的一部分:
将 android:hint 更改为 andoid:text 以便能够通过键盘使用文本。但是,如果键盘关闭,它仍然需要返回到第一个编辑文本,然后它将为第二个编辑文本保持打开状态。
我将使用高度作为两个编辑文本框的“wrap_content”。
<EditText
...
android:text="descriptionHint"
android:focusableInTouchMode="true"
android:textIsSelectable="true"
android:layout_weight="1"/>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7369 次 |
| 最近记录: |