<application android:name=".view.MyApp" android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme">
<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>
/**
* 初始化标题
*/
private void initActionbar() {
ActionBar actionBar= getSupportActionBar();//获取当前页面的标题栏
actionBar.setTitle("Demo应用");//设置显示标题
actionBar.setLogo(R.mipmap.ic_launcher);//设置logo标志
actionBar.setDisplayShowHomeEnabled(true);//是否显示在主页面上
actionBar.setDisplayUseLogoEnabled(true);//是否使用标志图片
actionBar.setDisplayHomeAsUpEnabled(true);//返回键
actionBar.show();//设置后调用show显示标题栏
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.action_bar_menu,menu);
return true;
}
<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <!--menu集合添加多个按钮 showAsAction 显示设置 always 争取显示 ifRoom根据剩余空间的大小来决定 ,大 就显示 ,反之 不显示 never 默认从来不显示在集合外面 app:showAsAction="always"--> <item android:id="@+id/menu1" android:title="菜单1" android:icon="@drawable/action_download"/> <item android:id="@+id/menu2" android:title="菜单2" android:icon="@drawable/ic_feedback"/> <item android:id="@+id/menu3" android:title="菜单3" app:showAsAction="never" android:icon="@drawable/ic_exit"/> </menu>
/**
*这是Activity提供处理标题元素的事件方法,返回true消费事件
*关键点:android.R.id.home 是系统分配置的返回的id
*/
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()){
case android.R.id.home: //这个id是固定的,系统分配的
if(mDrawerLayout.isDrawerOpen(mMenuLayout)){
//如果是打开状态,那么点击就关闭
mDrawerLayout.closeDrawer(mMenuLayout);
}else{
//如果是关闭状态,那么点击就打开
mDrawerLayout.openDrawer(mMenuLayout);
}
break;
case R.id.menu1:
Toast.makeText(this, item.getTitle(), Toast.LENGTH_SHORT).show();
break;
case R.id.menu2:
Toast.makeText(MyApp.getContext(), item.getTitle(), Toast.LENGTH_SHORT).show();
break;
case R.id.menu3:
UiUtils.showToast(item.getTitle().toString());
break;
}
return super.onOptionsItemSelected(item);
}
/**
* 设置箭头打开动画
*/
private void initRotateArrowAnimation() {
//参数1:Activity 参数2:抽屉控件 参数3,4:string
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this,mDrawerLayout,R.string.open,R.string.close);
//同步状态 作用:把返回图标替换 2,把旋转特效箭头跟抽屉关联
toggle.syncState();
//抽屉滑动的距离换成角度,使用箭头旋转
mDrawerLayout.addDrawerListener(toggle);
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有