在Android应用程序中实现Google Maps等搜索栏
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了在Android应用程序中实现Google Maps等搜索栏,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2589字,纯文字阅读大概需要4分钟。
内容图文
我正在构建一个使用Google Maps API的应用,我希望它在顶部有一个浮动搜索栏,与Google地图应用中的搜索栏完全相同.
我发现了Places Autocomplete,但是应用程序不会搜索地点,而是搜索用户将创建的另一种数据.
我还发现了一个名为Float Search View的库,但它已经停止了一段时间,因此我想传递一下.我也想手动创建它,因为这是我要构建的第一个Android应用程序,我想学习.
我尝试在我的XML中实现SearchView:
<android.support.v7.widget.SearchView
android:id="@+id/searchView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:iconifiedByDefault="false"
app:queryHint="@string/search_hint"
android:theme="@style/SearchBar"/>
白色背景和海拔:
<style name="SearchBar">
<item name="android:background">@color/colorPrimary</item>
<item name="android:elevation">4dp</item>
</style>
看看我是否可以接近它,但结果非常奇怪.
我尝试过添加工具栏等其他方法,但结果是一样的.
我想要一个像谷歌地图顶部搜索栏的结果.我该怎么做?
解决方法:
谷歌地图用户界面可能没什么特别之处.我的猜测是它是一个全屏幕MapView上的自定义视图.您可以通过在与全屏MapView相同的容器中使用类似工具栏的布局来执行类似的操作.
这是一个XML布局,可以帮助您入门:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.gms.maps.MapView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/red"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_add_24dp" />
<EditText
android:hint="Try gas stations, ATMs"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_search_24dp" />
</LinearLayout>
</android.support.v7.widget.CardView>
</android.support.constraint.ConstraintLayout>
这看起来像这样(想象红色是MapView的位置):
从这里开始,您只需根据需要设置“工具栏”的样式.
希望有所帮助!
内容总结
以上是互联网集市为您收集整理的在Android应用程序中实现Google Maps等搜索栏全部内容,希望文章能够帮你解决在Android应用程序中实现Google Maps等搜索栏所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。