我有一个EditText,它不允许聚焦和键入。屏幕具有CoordinatorLayout作为根/父级,以及带有ViewPager的NestedScrollView。
在顶部将有google map,在底部有两个标签。
第一个选项卡上的文本内容带有“编辑文本”(出现问题),第二个选项卡上有一个recyclerview。
在这种布局下,无法在“第一个”选项卡上的“焦点”和“编辑文本”上键入内容。
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="Fragments.JobOpen">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:elevation="0dp">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="@dimen/job_open_map_height"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimaryDark"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
app:titleEnabled="false">
<!--
TODO:: You may use fragment to load map just below the ImageView.
The ImageView is a placeholder I used during the design as a reference.
-->
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/gmap_screenshot"
app:layout_collapseMode="parallax"
android:contentDescription="@string/app_name" />
<!--
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.7" />
-->
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:id="@+id/job_open_nested_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:scrollbars="none"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"
android:focusableInTouchMode="true">
<android.support.design.widget.TabLayout
android:id="@+id/job_open_tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="@dimen/archive_card_elevation"
android:background="@color/colorLightGray"
app:layout_constraintBottom_toTopOf="@+id/job_open_viewpager"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
app:layout_constraintVertical_chainStyle="packed"
app:tabSelectedTextColor="@color/colorWhite"
app:tabTextColor="@color/colorFieldHint"
tools:targetApi="lollipop">
<!--
TODO:: Remove the tab items ...
I have kept it for your reference however it is useless here..
as loading from Viewpager class..
-->
<android.support.design.widget.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/job_details" />
<android.support.design.widget.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/services_providers" />
</android.support.design.widget.TabLayout>
<android.support.v4.view.ViewPager
android:id="@+id/job_open_viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/job_open_tab_layout" />
</android.support.constraint.ConstraintLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/app_space"
tools:context="Fragments.JobOpenDetails">
<TextView
android:id="@+id/job_open_id_label"
style="@style/TextLabel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/app_space_one_half"
android:text="@string/job_id"
app:layout_constraintBottom_toTopOf="@+id/job_open_service_label"
app:layout_constraintEnd_toEndOf="@id/job_open_elapsed_time_label"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
app:layout_constraintVertical_chainStyle="packed" />
<TextView
android:id="@+id/job_open_service_label"
style="@style/TextLabel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/app_space_one_half"
android:text="@string/problem"
app:layout_constraintBottom_toTopOf="@+id/job_open_elapsed_time_label"
app:layout_constraintEnd_toEndOf="@id/job_open_elapsed_time_label"
app:layout_constraintStart_toStartOf="@+id/job_open_id_label"
app:layout_constraintTop_toBottomOf="@+id/job_open_id_label" />
<TextView
android:id="@+id/job_open_elapsed_time_label"
style="@style/TextLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/app_space_one_half"
android:text="@string/elapsed_time"
app:layout_constraintBottom_toTopOf="@+id/job_open_time_label"
app:layout_constraintEnd_toStartOf="@id/job_open_content_barrier"
app:layout_constraintStart_toStartOf="@+id/job_open_id_label"
app:layout_constraintTop_toBottomOf="@+id/job_open_service_label" />
<TextView
android:id="@+id/job_open_time_label"
style="@style/TextLabel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/app_space_one_half"
android:text="Opened at"
app:layout_constraintBottom_toTopOf="@+id/job_open_vehicle_label"
app:layout_constraintEnd_toEndOf="@id/job_open_elapsed_time_label"
app:layout_constraintStart_toStartOf="@+id/job_open_id_label"
app:layout_constraintTop_toBottomOf="@+id/job_open_elapsed_time_label" />
<TextView
android:id="@+id/job_open_vehicle_label"
style="@style/TextLabel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/app_space_one_half"
android:text="@string/vehicle"
app:layout_constraintBottom_toTopOf="@+id/job_open_price_label"
app:layout_constraintEnd_toEndOf="@id/job_open_elapsed_time_label"
app:layout_constraintStart_toStartOf="@+id/job_open_id_label"
app:layout_constraintTop_toBottomOf="@+id/job_open_time_label" />
<TextView
android:id="@+id/job_open_price_label"
style="@style/TextLabel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/app_space_one_half"
android:text="@string/price"
app:layout_constraintBottom_toTopOf="@+id/job_open_note_label"
app:layout_constraintEnd_toEndOf="@id/job_open_elapsed_time_label"
app:layout_constraintStart_toStartOf="@+id/job_open_id_label"
app:layout_constraintTop_toBottomOf="@+id/job_open_vehicle_label" />
<TextView
android:id="@+id/job_open_note_label"
style="@style/TextLabel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/notes"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@id/job_open_elapsed_time_label"
app:layout_constraintStart_toStartOf="@+id/job_open_id_label"
app:layout_constraintTop_toBottomOf="@+id/job_open_price_label" />
<!-- separator -->
<android.support.constraint.Barrier
android:id="@+id/job_open_content_barrier"
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:barrierDirection="right"
app:constraint_referenced_ids="job_open_note,job_open_time,job_open_id,job_open_vehicle,job_open_service,job_open_price,job_open_elapsed_time"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/job_open_id"
app:layout_constraintStart_toEndOf="@id/job_open_elapsed_time_label"
app:layout_constraintTop_toTopOf="parent" />
<!-- values -->
<TextView
android:id="@+id/job_open_id"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:text="345"
app:layout_constraintBaseline_toBaselineOf="@+id/job_open_id_label"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/job_open_content_barrier" />
<TextView
android:id="@+id/job_open_service"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:text="Flat Tire"
app:layout_constraintBaseline_toBaselineOf="@+id/job_open_service_label"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/job_open_id" />
<TextView
android:id="@+id/job_open_elapsed_time"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:text="5min"
app:layout_constraintBaseline_toBaselineOf="@+id/job_open_elapsed_time_label"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/job_open_id" />
<TextView
android:id="@+id/job_open_time"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="12:30pm on 12-31-2019"
app:layout_constraintBaseline_toBaselineOf="@+id/job_open_time_label"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/job_open_id" />
<TextView
android:id="@+id/job_open_vehicle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Nissan March K13 2013 Purple"
app:layout_constraintBaseline_toBaselineOf="@+id/job_open_vehicle_label"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/job_open_id" />
<TextView
android:id="@+id/job_open_price"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="$40"
app:layout_constraintBaseline_toBaselineOf="@+id/job_open_price_label"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/job_open_id" />
<TextView
android:id="@+id/job_open_note"
style="@style/TextContent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="I am waiting in a hotel just after highway. Please contact me as you arive on spot."
app:layout_constraintBottom_toTopOf="@id/job_open_action_barrier"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/job_open_id"
app:layout_constraintTop_toTopOf="@+id/job_open_note_label"
app:layout_constraintVertical_bias="0.0" />
<android.support.constraint.Barrier
android:id="@+id/job_open_action_barrier"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:barrierDirection="bottom"
app:constraint_referenced_ids="job_open_note"
app:layout_constraintBottom_toTopOf="@+id/job_open_edit_button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/job_open_note" />
<Button
android:id="@+id/job_open_edit_button"
style="@style/ButtonFlat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/app_space_one_half"
android:text="@string/edit"
app:layout_constraintStart_toStartOf="@+id/job_open_id_label"
app:layout_constraintTop_toBottomOf="@+id/job_open_action_barrier" />
<Button
android:id="@+id/job_open_cancel_button"
style="@style/ButtonPostTheme"
android:layout_marginTop="@dimen/app_space_one_half"
android:text="@string/cancel"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/job_open_action_barrier" />
<EditText
android:id="@+id/test_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/job_open_cancel_button" />
</android.support.constraint.ConstraintLayout>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
tools:context="Fragments.JobOpenAppliedProviders">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/job_open_provider_sort_label"
style="@style/SortLabelText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/app_space"
android:text="@string/sort_by"
app:layout_constraintBaseline_toBaselineOf="@+id/job_open_provider_sorty_time"
app:layout_constraintEnd_toStartOf="@+id/job_open_provider_sorty_time"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="@+id/job_open_provider_sorty_time"
style="@style/BodyMenuText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/time"
app:layout_constraintBaseline_toBaselineOf="@+id/job_open_provider_sort_distance"
app:layout_constraintEnd_toStartOf="@+id/job_open_sort_divider"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/job_open_provider_sort_label" />
<View
android:id="@+id/job_open_sort_divider"
android:layout_width="@dimen/job_open_provider_sort_divider_thickness"
android:layout_height="@dimen/job_open_provider_sort_divider_height"
android:layout_marginStart="@dimen/app_space_half"
android:layout_marginEnd="@dimen/app_space_half"
android:background="@color/colorListItemBorder"
app:layout_constraintBottom_toBottomOf="@+id/job_open_provider_sort_distance"
app:layout_constraintEnd_toStartOf="@+id/job_open_provider_sort_distance"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/job_open_provider_sorty_time"
app:layout_constraintTop_toTopOf="@+id/job_open_provider_sort_distance" />
<TextView
android:id="@+id/job_open_provider_sort_distance"
style="@style/BodyMenuText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/app_space"
android:layout_marginEnd="@dimen/app_space"
android:layout_marginBottom="@dimen/app_space_one_half"
android:text="@string/distance"
app:layout_constraintBottom_toTopOf="@id/job_open_provider_barrier"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/job_open_sort_divider"
app:layout_constraintTop_toTopOf="parent" />
<android.support.constraint.Barrier
android:id="@+id/job_open_provider_barrier"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:barrierDirection="bottom"
app:layout_constraintBottom_toTopOf="@id/job_open_provider_list"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/job_open_provider_sort_distance" />
<android.support.v7.widget.RecyclerView
android:id="@+id/job_open_provider_list"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/job_open_provider_barrier" />
</android.support.constraint.ConstraintLayout>
</android.support.v4.widget.NestedScrollView>
答案 0 :(得分:0)
您可以强制编辑文本以编程方式获得焦点。在TAB1 Java类中,您可以执行以下操作,以强制编辑文本获得焦点。
EditText editText = findViewById(R.id.test_text); //initialize edit text
editText.requestFocus(); //will request focus
//will force the keyboard to show
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);