我試圖建立聊天界面。我已經編寫了用於記錄fab.my動畫的聲音的代碼,當我按下按鈕,並且我的edittext將焦點放在edittext上,無故失去了將鍵盤上的自動檢測詞條隱藏起來的焦點, 1釐米的鍵盤。我知道這個問題是由於回收視圖,因爲當我只是設置回收站視圖的可見性去掉edittext不要失去焦點,當我嘗試記錄。我也試圖改變windowSoftInputMode。謝謝您的幫助。EditText失去焦點,如果我打記錄按鈕
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/relativeLayout_chat_background"
android:layout_width="wrap_content"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<com.example.fcb.insurance.customViews.holdingbutton.HoldingButtonLayout
android:id="@+id/input_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
app:hbl_cancel_icon="@drawable/ic_clear_white_24dp"
app:hbl_color="@color/colorAccent"
app:hbl_holding_view="@+id/start_record"
app:hbl_icon="@drawable/ic_mic_white_24dp"
app:hbl_radius="@dimen/activity_main_holding_button_radius"
app:hbl_second_radius="@dimen/activity_main_holding_button_second_radius"
android:layout_toLeftOf="@+id/sendMessage"
android:paddingRight="10dp"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:clipChildren="false"
android:clipToPadding="false" >
<LinearLayout
android:id="@+id/slide_to_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|end"
android:layout_marginEnd="@dimen/activity_main_slide_to_cancel_margin_right"
android:layout_marginRight="@dimen/activity_main_slide_to_cancel_margin_right"
android:gravity="center_vertical"
android:visibility="invisible">
<ImageView
android:layout_width="@dimen/activity_main_slide_to_cancel_icon_size"
android:layout_height="@dimen/activity_main_slide_to_cancel_icon_size"
android:layout_marginEnd="@dimen/activity_main_slide_to_cancel_icon_margin_right"
android:layout_marginRight="@dimen/activity_main_slide_to_cancel_icon_margin_right"
android:scaleType="center"
android:src="@drawable/ic_keyboard_arrow_left_black_24dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/label_slide_to_cancel"/>
<TextView
android:id="@+id/textView_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:textColor="@color/colorAccent"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:minHeight="@dimen/activity_main_input_holder_min_height"
android:orientation="horizontal"
>
<EditText
android:id="@+id/editText_message"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/activity_main_input_margin_left"
android:layout_marginStart="@dimen/activity_main_input_margin_left"
android:paddingLeft="16dp"
android:layout_weight="1"
android:hint="@string/hint_type_your_message"
android:paddingBottom="@dimen/activity_main_input_padding_vertical"
android:paddingTop="@dimen/activity_main_input_padding_vertical"
android:textSize="@dimen/activity_main_input_text_size"
android:background="@drawable/chat_input_text"
android:maxLines="6"
android:scrollbarStyle="insideInset"
android:scrollbars="vertical"
android:layout_gravity="bottom"
></EditText>
<android.support.design.widget.FloatingActionButton
android:id="@+id/start_record"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/Widget.AppCompat.Button.Borderless.Colored"
android:src="@drawable/ic_mic_white_24dp"
android:layout_marginLeft="10dp"
android:layout_gravity="bottom"
/>
</LinearLayout>
</com.example.fcb.insurance.customViews.holdingbutton.HoldingButtonLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/sendMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/Widget.AppCompat.Button.Borderless.Colored"
android:src="@drawable/ic_send_white_24dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:visibility="gone"
/>
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView_chat_item_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/input_holder"
android:layout_marginEnd="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginStart="5dp"
android:clipToPadding="false"
android:paddingTop="8dp"
android:visibility="visible"
app:layoutManager="LinearLayoutManager"
tools:listitem="@layout/item_chat_list_out"
/>
</RelativeLayout>
已經嘗試過這種出於某種原因拒絕獲得焦點 –
儘量做到 機器人:可調焦=「真」 在XML – Elsunhoty
沒有達到預期效果。 –