系统键盘和表情切换

思路:

1.默认键盘模式设置为adjustResize;

2.获取键盘的高度,设置给表情控件;

3.要显示表情控件时,先将键盘模式设置为ADJUST_NOTHING,表情控件设置为可见,再隐藏键盘;

4.要显示键盘时,先调用显示键盘,延时隐藏表情控件,并将键盘模式设置为ADJUST_RESIZE。

布局:


```java
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity2">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:orientation="horizontal">

            <EditText
                android:id="@+id/edit"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="@null"
                android:hint="我是输入框"
                android:textColor="#00aaaa"
                android:textSize="18sp" />

            <ImageView
                android:id="@+id/image_face"
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:src="@drawable/ic_smile" />
        </LinearLayout>

        <TextView
            android:id="@+id/text_fake_face"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_alignParentBottom="true"
            android:background="#fafa00"
            android:gravity="center"
            android:text="假装是表情包"
            android:visibility="gone"
            tools:visibility="visible" />
    </LinearLayout>
</RelativeLayout>

代码如下:

public class MainActivity2 extends AppCompatActivity {
   

    private ImageView mFaceImage;
    private View mFakeFaceView;
    private InputMethodManager inputMethodManager;
    private EditText mEdit;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
   
        super.onCreate(savedInstanceState);
        setContentView(
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值