Java 创建搜索框式材质设计2018
我想在Android Studio项目中创建一个类似于谷歌地图应用程序搜索框的搜索框。我该怎么做?有样品可以复制吗? 谢谢你的建议 这是Java 创建搜索框式材质设计2018,java,android,android-layout,android-studio,Java,Android,Android Layout,Android Studio,我想在Android Studio项目中创建一个类似于谷歌地图应用程序搜索框的搜索框。我该怎么做?有样品可以复制吗? 谢谢你的建议 这是 您可以使用框架布局作为搜索框,并将其替换为自定义片段 这是您附加的搜索框的示例代码 搜索框片段布局 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:lay
您可以使用
框架布局
作为搜索框,并将其替换为自定义片段
这是您附加的搜索框的示例代码
搜索框片段布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="42dp"
android:layout_margin="16dp"
android:background="@drawable/search_box_style"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:src="@drawable/ic_dehaze_black_24dp" />
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:padding="8dp"
android:layout_weight="1"
android:background="#00ffffff"
android:gravity="center_vertical" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:src="@drawable/ic_mic_black_24dp" />
</LinearLayout>
你可以为你的
片段
项目设置监听器
。而不是自己创造一切,这是一种重新发明轮子,您可以使用开放源代码库,它不仅让您轻松创建searchview,而且还允许您对其进行样式设置,并且当您自己进行所有操作时,还可以使用许多其他复杂的选项来访问它。
下面是一个屏幕截图,显示了此库的功能:
否则,您可以使用Android组件,设置一些背景并添加样式,使其看起来像您想要的。是的,您可以使用cardview创建。它很容易用Cardlayout和它的立面创建。你检查过他们有你可以使用的组件吗use@MadhanVaradhodiyil我查过了,但没找到it@clooock这个->?非常感谢,我会这样做的!
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#ffffff" />
<stroke
android:width="0.1dp"
android:color="#7b7b7b" />
<corners android:radius="4dp" />
</shape>