0

我有一个自定义的屏幕后退按钮,一旦用户点击我屏幕的 EditText,我想将其更改为“隐藏键盘”。我从这个问题中找到了一些很好的代码,关于检测键盘是否打开(查看 Reuben Scratton 的旧答案了解我所做的事情)。我在 .java 文件中的步骤:

 @Override
public void onSoftKeyboardShown(boolean isShowing) {
    // do whatever you need to do here
}

一旦键盘打开,我将如何在此处输入后退按钮的代码以更改其图像?

这是我当前的后退按钮的代码:

    <ImageButton
        android:id="@+id/back"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@null"
        android:contentDescription="Back"
        android:scaleType="fitStart"
        android:src="@drawable/back_bar" />

我想将其更改为:

 <ImageButton
        android:id="@+id/back"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@null"
        android:contentDescription="Back"
        android:scaleType="fitStart"
        android:src="@drawable/hide_keyboard" />

这是我正在尝试做的事情的图像,以防我没有任何意义! 图片

4

1 回答 1

0

你可以使用:

ImageButton backButton = (ImageButton)findViewById(R.id.back); 
backButton.setImageResource(R.drawable.hide_keyboard);

在你的onSoftKeyboardShown方法中

于 2013-01-12T21:02:08.747 回答