Android -- 案例学习积累
Theme
ActionBar / ToolBar
android.support.design.widget.CollapsingToolbarLayout
android.support.design.widget.AppBarLayout
@、Theme
1、设置NoActionBar
<resources>
<!-- Base application theme. -->
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#3F51B5</item>
<!-- Light Indigo -->
<item name="colorPrimaryDark">#3949AB</item>
<!-- Dark Indigo -->
<item name="colorAccent">#00B0FF</item>
<!-- Blue -->
</style>
<style name="AppTheme" parent="AppTheme.Base"></style>
</resources>
@、ActionBar / ToolBar
1、Theme设置为NoActionBar,Layout文件中添加
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
然后再代码中设置此Toolbar为ActionBar
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar); // 设置ActionBar
ActionBar supportedActionBar = getSupportActionBar();
if(supportedActionBar != null){
// 设置向上导航的图标。默认为向左的箭头
supportedActionBar.setHomeAsUpIndicator(R.drawable.ic_menu_white_24dp);
// 设置是否显示向上导航: true显示,false不显示;默认为false.
supportedActionBar.setDisplayHomeAsUpEnabled(true);
}
相关知识:
a、如果没有在onOptionsItemSelected中对android.R.id.home进行处理,则:在AndroidManifest中相应的activity指定了android:parentActivityName,就返回到parentActivity,否则什么都不做。
b、如果是返回parentActivity,则parentActivity会onDestroy, onCreate, onStart, onResume执行一遍。而如果是按返回键,则只是(onStart), onResume。对于主界面有Tab页的时候要注意考虑这种情况。
c、在onOptionsItemSelected进行判断,如果是android.R.id.home,则直接调用finish(),这样也可以到达按返回键的效果。当然如果onBackPressed()没有做特殊处理的话,也可以调用onBackPressed()。
d、应用场景:使用此方法为侧边导航栏添加指示器。
@、android.support.design.widget.CollapsingToolbarLayout
1、对Tookbar进行包装。
2、如果collaspsingToolbarLayout的app:layout_scrollFlags设置为exitUntilCollasped,则对子控件设置app:layout_collapseMode:pin(固定不动,Toolbar上的向上导航和菜单按钮不会消失), parallax(随着CollapsingToolbarLayout移动而移动,Toolbar上的向上导航和菜单按钮会消失),不过最后的高度和宽度就是Toobar的高度和宽度。
3、app:contentScrim指定了最终显示的内容。
@、android.support.design.widget.AppBarLayout
原来这些实现是需要CoordinatorLayout的配合,在使用中竟然没有注意到这点,看了这篇文章,总算有所明白了:Handling Scrolls with CoordinatorLayout。
1、对子控件设置app:layout_scrollFlags:sroll(向上滑(滚动条向下滑),子控件一起向上滑), enterAlways(向下滑(滚动条向上滑),不管滚动条是否滑到顶,子控件都出现,如果不指定该值,则要等滚动条滑到顶,子控件才会出现), enterAlwaysCollasped(这个没有测试出有什么用??), exitUntilCollasped(结合CollapsingToolbarLayout使用,如果CollapsingToolbarLayout的Toolbar把app:layout_collapseMode设置为pin,则该Toolbar上的向上导航和菜单按钮不会消失)。
示例一:AppBarLayout + Toolbar + TabLayout,滑动时Toolbar隐藏,Tab标签保留
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<!-- 配合Theme设置为Theme.AppCompat.Light.NoActionBar使用,这样ActionBar的文字就是浅色的了 -->
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> <android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.AppBarLayout>
示例二: AppBarLayout + CollapsingToolbarLayout + Toolbar
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="256dp"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> <android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginEnd="72dp"
app:expandedTitleMarginStart="16dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed"> <ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"
tools:background="@drawable/a"/> <android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="parallax"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/> </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
Android -- 案例学习积累的更多相关文章
- Android WiFiDirect 学习(二)——Service Discovery
Service Discovery 简介 在Android WifiDirect学习(一 )中,简单介绍了如何使用WifiDirect进行搜索——连接——传输. 这样会有一个问题,那就是你会搜索到到附 ...
- Android开发学习之路-RecyclerView滑动删除和拖动排序
Android开发学习之路-RecyclerView使用初探 Android开发学习之路-RecyclerView的Item自定义动画及DefaultItemAnimator源码分析 Android开 ...
- Android开发学习路线图
Android开发学习方法: Android是一个比较庞大的体系,从底层的Linux内核到上层的应用层,各部分的内容跨度也比较大.因此,一个好的学习方法对我们学习Android开发很重要. 在此建议, ...
- Android动画学习(二)——Tween Animation
前两天写过一篇Android动画学习的概述,大致的划分了下Android Animation的主要分类,没有看过的同学请移步:Android动画学习(一)——Android动画系统框架简介.今天接着来 ...
- Storm入门2-单词计数案例学习
[本篇文章主要是通过一个单词计数的案例学习,来加深对storm的基本概念的理解以及基本的开发流程和如何提交并运行一个拓扑] 单词计数拓扑WordCountTopology实现的基本功能就是不停地读入 ...
- Android自动化学习笔记:编写MonkeyRunner脚本的几种方式
---------------------------------------------------------------------------------------------------- ...
- Android自动化学习笔记之MonkeyRunner:官方介绍和简单实例
---------------------------------------------------------------------------------------------------- ...
- android开发学习笔记000
使用书籍:<疯狂android讲义>——李刚著,2011年7月出版 虽然现在已2014,可我挑来跳去,还是以这本书开始我的android之旅吧. “疯狂源自梦想,技术成就辉煌.” 让我这个 ...
- Android Animation学习(六) View Animation介绍
Android Animation学习(六) View Animation介绍 View Animation View animation系统可以用来执行View上的Tween animation和F ...
随机推荐
- cosbench 异常 FreeMarker template error: The following has evaluated to null or missing
问题现象: 使用Cosbench 0.4.2.c4 版本测试Ceph RGW read test失败,遇到异常如下: FreeMarker template error: The following ...
- Uninstall from GAC In C# code
How do I uninstall the GAC from my C# application. I am not able to uninstall, the particular exe an ...
- 利用phpize 外挂php扩展
如果你的php是手动编译安装的 ,可能有一些扩展一开始并没有开启,以后需要某扩展的时候又不想重新编译php,使用phpize可以动态添加扩展 以Ubuntu为例, 如果你是我这样安装php的 apt ...
- 如何完全卸载(Mac&Windows)office 365 ProPlus
Q: 如何完全卸载office 365 ProPlus,如果用户使用之前的office版本没有卸载干净(配置文件中保持了原有的Key)会造成新安装的office 365 ProPlus 或者最新版的o ...
- ORACLE 中的 ROW_NUMBER() OVER() 分析函数的用法
ORACLE 中的 ROW_NUMBER() OVER() 分析函数的用法 ROW_NUMBER() OVER(partition by col1 order by col2) 表示根据col1分组, ...
- iOS多线程学习
在 iOS 中其实目前有 4 套多线程方案,他们分别是: Pthreads NSThread GCD NSOperation & NSOperationQueue 所以接下来,我会一一讲解这些 ...
- iOS获取设备唯一标识的8种方法
8种iOS获取设备唯一标识的方法,希望对大家有用. UDID UDID(Unique Device Identifier),iOS 设备的唯一识别码,是一个40位十六进制序列(越狱的设备通过某些工具可 ...
- linux 命令行 光标移动技巧
linux 命令行 光标移动技巧 看一个真正的专家操作命令行绝对是一种很好的体验-光标在单词之间来回穿梭,命令行不同的滚动.在这里强烈建立适应GUI节目的开发者尝试一下在提示符下面工作.但是事情也不是 ...
- 调整Virtual Box硬盘大小
我在Mac下使用Virtual Box安装Win7的虚拟机.因为之前装过Win7的32位版.现在因为机器内存升到8G,就可以划出4G来支持Win7虚拟机.所以就重新安装了Win7的64位版.在创建虚拟 ...
- golang笔记——流程控制
条件语句 if ... else if ... else 语句,如: { fmt.Println(">100") } < num { fmt.Println(" ...