| Android的标题栏是很重要的一个模块,App是否易用很大一部分要看标题栏。写这个博客的时候刚发现谷歌推出了一种新的标题栏实现方式。 它相对于以前的ActionBar来说,最大的变化是开发者可以在标题栏上增加自定义的view。同时在最左端添加了一个导航按钮。 
 
<activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
 
<android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />
    </android.support.design.widget.AppBarLayout>
 
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context="com.example.administrator.gattbluethoothdemo.MainActivity">
    <item
        android:id="@+id/action_settings"
        android:orderInCategory="100"
        android:title="设置"
        app:showAsAction="never" />
    <item android:id="@+id/menu_refresh"
        android:title="更新"
        android:checkable="false"
        android:orderInCategory="1"
        app:showAsAction="ifRoom"/>
    <item android:id="@+id/menu_scan"
        android:title="扫描"
        android:orderInCategory="100"
        app:showAsAction="ifRoom|withText"/>
    <item android:id="@+id/menu_stop"
        android:title="停止"
        android:orderInCategory="101"
        app:showAsAction="ifRoom|withText"/>
</menu>
 
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        toolbar.setTitle("扫描界面");
        toolbar.setSubtitle("子标题");
        //设置导航栏图标
        toolbar.setNavigationIcon(R.mipmap.ic_launcher);
        //设置程序logo
        toolbar.setLogo(R.mipmap.ic_launcher);
        //设置Toolbar像ActionBar一样实现,
        setSupportActionBar(toolbar);接着就和ActionBar一样, 
@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
           Toast.makeText(MainActivity.this,"请设置",Toast.LENGTH_SHORT).show();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }(责任编辑:最模板) | 



 ecshop红酒模板|红酒程序源
							人气:859
							ecshop红酒模板|红酒程序源
							人气:859
						 Ecmall仿亚马逊英文外贸多
							人气:1755
							Ecmall仿亚马逊英文外贸多
							人气:1755
						 ecshop转盘积分抽奖插件
							人气:7377
							ecshop转盘积分抽奖插件
							人气:7377
						 仿2011麦包包shopex模板
							人气:810
							仿2011麦包包shopex模板
							人气:810
						 ecshop仿和茶2013宽屏茶叶网
							人气:8844
							ecshop仿和茶2013宽屏茶叶网
							人气:8844
						 免费某ecshop商ecshop微信商
							人气:21709
							免费某ecshop商ecshop微信商
							人气:21709