新闻类客户端代码阅读笔记

ButterKnife

这个开源库可以让我们从大量的findViewById()和setonclicktListener()解放出来

@Bind(R.id.toolbar) Toolbar toolbar;
//相当于 Toolbar toolbar=(Toolbar) findViewById(R.id.toolbar
@Bind({R.id.tab_news, R.id.tab_pictures, R.id.tab_found, R.id.tab_about})
    List<RadioButton> mTabs;
    private Fragment mTab01;
    private Fragment mTab02;
    private Fragment mTab03;
    private Fragment mTab04;
//相当于实现多个组件的注册声明  mTab01放于mTabs.get(0)
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);         //将上诉声明绑定到这个activity,就相当于 在这里 findViewById;
    }

Toolbar

Toolbar是在 Android 5.0 开始推出的一个 Material Design 风格的导航控件 ,Google 非常推荐大家使用 Toolbar 来作为Android客户端的导航栏,以此来取代之前的 Actionbar 。与 Actionbar 相比, Toolbar 明显要灵活的多。它不像 Actionbar 一样,一定要固定在Activity的顶部,而是可以放到界面的任意位置。除此之外,在设计 Toolbar 的时候,Google也留给了开发者很多可定制修改的余地,这些可定制修改的属性在API文档中都有详细介绍,如:

设置导航栏图标;
设置App的logo;
支持设置标题和子标题;
支持添加一个或多个的自定义控件;
支持Action Menu;

<android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:minHeight="?attr/actionBarSize"  //设置最小高度
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"/>

最后再附上一个界面上常用的属性说明图:

这里写图片描述

这里按照图中从上到下的顺序做个简单的说明:

colorPrimaryDark

状态栏背景色。
在 style 的属性中设置。
textColorPrimary

App bar 上的标题与更多菜单中的文字颜色。
在 style 的属性中设置。
App bar 的背景色

Actionbar 的背景色设定在 style 中的 colorPrimary。
Toolbar 的背景色在layout文件中设置background属性。
colorAccent

各控制元件(如:check box、switch 或是 radoi) 被勾选 (checked) 或是选定 (selected) 的颜色。
在 style 的属性中设置。
colorControlNormal

各控制元件的预设颜色。
在 style 的属性中设置
windowBackground

App 的背景色。
在 style 的属性中设置
navigationBarColor

导航栏的背景色,但只能用在 API Level 21 (Android 5) 以上的版本
在 style 的属性中设置

setCompoundDrawablesWithIntrinsicBounds(Drawable left, Drawable top, Drawable right, Drawable bottom)
//将图标设置在文字的上、下、左、右位置
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值