【问题标题】:Add two Buttons to the Soft Keyboard向软键盘添加两个按钮
【发布时间】:2017-11-09 06:24:57
【问题描述】:

我可以在软键盘上添加一个完成按钮,但我也想添加一个 Del 按钮,如果可以,请告诉我怎么做?

【问题讨论】:

    标签: android android-edittext keypad


    【解决方案1】:

    创建 sample.xml 布局文件

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="match_parent"
        android:layout_height="match_parent">
        <LinearLayout
            android:layout_alignParentBottom="true"
            android:gravity="bottom"
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <EditText
                android:gravity="left"
                android:background="#e4e4e4"
                android:layout_width="0dp"
                android:layout_weight="8"
                android:layout_height="match_parent" />
            <LinearLayout
                android:orientation="vertical"
                android:layout_weight="2"
                android:layout_width="0dp"
                android:layout_height="wrap_content">
                <Button
                    android:text="Done"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />
                <Button
                    android:text="Del"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />
            </LinearLayout>
        </LinearLayout>
    </RelativeLayout>
    

    创建 Sample.java 活动文件

    public class Sample extends Activity {
        @Override
        protected void onCreate(@Nullable Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.sample);
        }
    }
    

    确保在清单文件中添加android:windowSoftInputMode="adjustResize",如下所示。

    <activity android:name=".Sample"
               android:windowSoftInputMode="adjustResize">
    </activity>
    

    【讨论】:

    • 不仅一个Activity需要客户软键盘,我希望它会在其他Activity中使用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-17
    • 1970-01-01
    • 2011-08-25
    • 1970-01-01
    相关资源
    最近更新 更多