有很多方法,没详细去尝试,而我的方法是在每个item添加一个hideKeyboard,hideKeyboard是自定义方法,此方法写在activity中
public void hideKeyboard(View view) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
适配器引用的xml的根节点写入android:onClick="hideKeyboard"(如果想要触发onclick最好不要在根节点添加外间距,可以包多一层写内间距)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/layout_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorWhite"
android:orientation="vertical"
android:paddingVertical="@dimen/dp_16"
android:layout_marginBottom="@dimen/dp_6"
android:onClick="hideKeyboard">
<EditText
android:id="@+id/edit_count"
android:layout_width="@dimen/dp_84"
android:layout_height="@dimen/dp_35"
android:layout_marginStart="@dimen/dp_10"
android:background="@drawable/round_edit_text_gray_bg"
android:inputType="number"
android:text="0"
android:textAlignment="center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="@dimen/dp_10"
android:text="现库存:"
android:textSize="@dimen/font_small" />
<TextView
android:id="@+id/current_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="10"
android:textSize="@dimen/font_small" />
</LinearLayout>
<font color=red>注意:内部其他控件添加android:clickable="true",父级点击事件会失效</font>
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有