从TextView中删除焦点

时间:2018-03-10 14:47:32

标签: android string android-activity textview focus

单击ListView项目,它会指示我进行第二项活动。在这个活动中,我有三个TextView,一个搜索栏和一个imageview。第三个TextView有一个很长的描述性文本。

问题出在我第二次活动时;它首先关注第三个TextView。但它应该集中在最顶级的TextView。

如何关注最顶层的TextView或确保从最顶层的TextView显示活动?

Figure of the problem: when second activity starts

这是布局xml代码:

<RelativeLayout 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:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="5dp"

tools:context=".ReadingStoryActivity">

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/scrollView2">

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

        <TextView
            android:id="@+id/text_story_name"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"
            android:layout_marginTop="10dp"
            android:fontFamily="sans-serif-condensed"
            android:gravity="center_horizontal"
            android:text="text_story_name"
            android:textAllCaps="true"
            android:textSize="18sp"
            android:textStyle="bold">

        </TextView>

        <TextView
            android:id="@+id/text_author_name"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="text_author_name"
            android:textAlignment="center"
            android:textSize="16sp"
            android:textStyle="bold|italic" />

        <Space
            android:layout_width="match_parent"
            android:layout_height="5dp"
            android:background="#000000"

            />

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="match_parent"
            android:layout_height="5dp"
            android:background="#000000"
            app:srcCompat="?attr/actionModeSplitBackground" />

        <SeekBar
            android:id="@+id/seekBar_"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:thumb="@drawable/bar"
            android:layout_below="@+id/imageView2"

            android:layout_marginTop="1dp" />

        <TextView
            android:id="@+id/text_body_story"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"


            android:padding="10dp"
            android:text="text_body_story"
            android:textColorHighlight="#ffee04"
            android:textIsSelectable="true"
            android:textSize="14sp" />

    </LinearLayout>


</ScrollView>


<com.google.android.gms.ads.AdView xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:id="@+id/adView2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    ads:adSize="SMART_BANNER"
    ads:adUnitId="ca-app-pub-4xxxxxxxxxxxxxx" />

</RelativeLayout>

1 个答案:

答案 0 :(得分:0)

在这种情况下,系统重点关注textview。您可以在android:focusableInTouchMode="true"中添加LinearLayout,以便获得焦点。

  <ScrollView
        android:id="@+id/scrollView2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <LinearLayout
            android:focusableInTouchMode="true"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
相关问题