一步步实现一个城市选择器详解.docVIP

  • 23
  • 0
  • 约2.29万字
  • 约 22页
  • 2017-03-31 发布于湖北
  • 举报
一步步实现一个城市选择器 主要包含以下内容: 1、自动定位所在城市 2、热门城市列表展示 3、所有城市列表的展示 4、输入城市名或者城市拼音搜索对应城市 5、右侧的slidebar城市列表导航栏 请大家先下载Demo然后再一边看demo一边看博客。因为博客里很多代码因为比较简单就不贴了。 首先我们先搭建基本的UI: 分析效果图,我们需要一个顶部title view,一个搜索框,一个定位功能的view,一个展示热门城市的view,一个侧边栏view和一个listview。 顶部title View: 这里有一些需要注意的地方: 我们在新建工程的时候,Android studio会自动生成一个style作为我们的主题: style name=AppTheme parent=Theme.AppCompat.Light.DarkActionBar !-- Customize your theme here. -- item name=colorPrimary@color/colorPrimary/item item name=colorPrimaryDark@color/colorPrimaryDark/item item name=colorAccent@color/colorAccent/item /style android:theme=@style/AppTheme 这个默认的主题是带有actionbar的,如果我们要去掉这个actionbar,首先需要把DarkActionBar改为NoActionBar,因为使用AppCompatActivity的时候,Activity必须使用Theme.AppCompat主题及其子主题,所以我们的自定义的HD_NoActionBar样式必须继承这个主题: style name=AppTheme parent=Theme.AppCompat.Light.NoActionBar !-- Customize your theme here. -- item name=colorPrimary@color/colorPrimary/item item name=colorPrimaryDark@color/colorPrimaryDark/item item name=colorAccent@color/colorAccent/item /style style name=HD_NoActionBar parent=AppTheme item name=android:windowNoTitletrue/item item name=android:windowActionBarfalse/item /style 然后引用这个style: android:theme=@style/AppTheme.NoActionBar 接下来写我们的头布局 title_view.xml: LinearLayout xmlns:android=/apk/res/android xmlns:tools=/tools android:layout_width=match_parent android:layout_height=wrap_content android:orientation=vertical RelativeLayout android:layout_width=match_parent android:layout_height=?attr/actionBarSize android:background=@color/light_blue ImageView android:id=@+id/back style=@style/Widget.AppCompat.ActionButton android:layout_width=wrap_content android:layout_height=match_parent android:paddingLeft=16dp android:paddingRight=16dp android:scaleType=center android:src=@mipmap/ic_back tools:ignore=ContentDescription / TextView android:layout_width=wrap_content an

文档评论(0)

1亿VIP精品文档

相关文档