简体   繁体   English

自定义外观searchView android

[英]Custom looking searchView android

I need to create a custom looking SearchView that opens when an ImageButton, that I already have in my MainActivity.xml, is pressed. 我需要创建一个自定义外观的SearchView,当按下MainActivity.xml中已经具有的ImageButton时,该ViewView将打开。

I would really appreciate if you could explain me how to do it, because all I could find on SO was either people not having a custom looking SearchView or having it permanently on their TitleBar which I do not have since I'm using the light.NoTitleBar theme. 如果您能解释一下该怎么做,我将不胜感激,因为我在SO上只能找到没有自定义外观的SearchView或将其永久地放在他们的TitleBar上的人,这是我使用光以来一直没有的。 NoTitleBar主题。

This is what I would need it to look like, this is a design I made with photoshop: 这是我需要的样子,这是我用photoshop制作的设计:

搜索

You have mutliple ways to obtain what you are looking for in term of design. 您可以通过多种方式获得想要的设计信息。

A solution i use (wich may not be the best) is to put my EditText (your search field) in a FrameLayout, this way i can have a search button and delete text button overlapping my textView: 我使用的解决方案(可能不是最好的)是将EditText(您的搜索字段)放在FrameLayout中,这样我可以有一个搜索按钮,并删除与textView重叠的文本按钮:

XML Example : XML范例:

<FrameLayout
 android:id="@+id/SearchTextInputLayout"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:layout_gravity="center"
 android:minWidth="100.0dp">
  <EditText
   android:id="@+id/SearchTextInput"
   android:textColorHint="@layout/inputselector"
   android:hint="Search terms here..."
   android:textAppearance="?android:attr/textAppearanceMedium"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   />
    <Button
      android:id="@+id/ClearSearchButton"
      android:layout_width="25dp"
      android:layout_height="25dp"
      android:layout_marginEnd="10dp"
      android:layout_marginRight="10dp"
      android:layout_gravity="end|center_vertical"
      android:background="@android:drawable/ic_delete" />
</FrameLayout>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM