簡體   English   中英

無法刪除android中自動完成片段中的搜索按鈕

[英]Not able to remove search button in Auto complete Fragment in android

我正在使用自動完成片段使用谷歌位置搜索位置它工作正常。 現在我想刪除在代碼下面使用的搜索圖標,但顯示一個錯誤。 代碼和錯誤文本如下。

代碼示例

autocompleteFragment.getView().findViewById(R.id.place_autocomplete_search_button).setVisibility(View.GONE);

xml :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
>
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="60dp"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:background="@drawable/header">
    <Button
        android:id="@+id/button5"
        android:layout_width="60dp"
        android:background="#1d1d6e"
        android:textColor="#9999f9"
        android:layout_height="25dp"
        android:textSize="13sp"
        android:text="@string/back"
        android:textAllCaps="false"
        android:layout_centerVertical="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginLeft="19dp"
        android:layout_marginStart="19dp" />

    <ImageView
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_centerInParent="true"
        android:layout_weight="1"
        android:src="@drawable/logo" />
</RelativeLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="35dp"
    android:background="@color/gray"
    android:orientation="horizontal">
    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:layout_marginLeft="15dp"
        android:layout_gravity="center"
        android:textColor="@color/black"
        android:text="ADD LOCATION" />
</LinearLayout>
<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="40dp"
    android:layout_marginLeft="15dp"
    android:layout_marginRight="15dp"
    android:layout_marginTop="10dp"
    >
    <EditText
        android:id="@+id/flat_no"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="textPersonName"
        android:hint="Flat Number/House Name"
        android:paddingLeft="10dp"
        android:background="@drawable/locationedittext"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="40dp"
    android:layout_marginLeft="15dp"
    android:layout_marginRight="15dp"
    android:background="@drawable/locationedittext"
    android:layout_marginTop="10dp"
    >

    <fragment
        android:id="@+id/autocomplete_fragment"
        android:name="com.google.android.libraries.places.widget.AutocompleteSupportFragment"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="40dp"
    android:layout_marginLeft="15dp"
    android:layout_marginRight="15dp"
    android:layout_marginTop="10dp"
    >

    <EditText
        android:id="@+id/makani"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="textPersonName"
        android:hint="Search By Makani"
        android:paddingLeft="10dp"
        android:background="@drawable/locationedittext"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/makanibutton"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_marginTop="10dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginBottom="10dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="@+id/makani"
        app:layout_constraintTop_toTopOf="parent"
        android:background="@android:drawable/ic_search_category_default" />
</androidx.constraintlayout.widget.ConstraintLayout>

<Button
    android:id="@+id/button8"
    android:layout_width="match_parent"
    android:layout_marginTop="10dp"
    android:layout_marginRight="15dp"
    android:layout_marginLeft="15dp"
    android:background="@drawable/startbutton"
    android:layout_height="40dp"
    android:text="SUBMIT"
    android:textColor="@color/white"/>

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="10dp">

    <LinearLayout
        android:id="@+id/linearLayout"
        android:layout_width="match_parent"
        android:layout_height="35dp"
        android:background="@color/gray"
        android:orientation="horizontal"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginLeft="15dp"
            android:layout_weight="1"
            android:text="LOCATION LIST"
            android:textStyle=""
            android:textColor="@color/black" />
    </LinearLayout>

    <ListView
        android:id="@+id/locationlist"
        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/linearLayout" />
</androidx.constraintlayout.widget.ConstraintLayout>

錯誤文本

錯誤:找不到符號變量 place_autocomplete_search_button

我還想更改自動完成片段的提示文本大小

請遷移到最新的 SDK並使用AutoCompleteSupportFragment而不是AutoCompleteFragment

有關遷移的完整信息,您可以參考此處。

遷移隱藏搜索按鈕后,id 是,

place_autocomplete_search_button用於搜索Button

Places_autocomplete_search_input用於EditText

所以你的代碼會有點類似於這個,

autocompleteSupportFragment.getView().findViewById(R.id.places_autocomplete_search_button).setVisibility(View.GONE);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM