toolbar

 toolbar= (Toolbar) findViewById(R.id.toolbar_mainactivity);
// 设置主标题及其颜色
toolbar.setTitle("AndroidViewDemo");
toolbar.setTitleTextColor(Color.WHITE);
// // 设置次标题及其颜色
// toolbar.setSubtitle("AigeStudio");
// toolbar.setSubtitleTextColor(Color.LTGRAY);
//
// // 设置导航按钮
// toolbar.setNavigationIcon(R.mipmap.action_bar_icon);
// toolbar.setNavigationOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View v) {
// MainActivity.this.finish();
// }
// });
// // 设置Logo图标
//// toolbar.setLogo(R.mipmap.ic_launcher);
//
// // 设置菜单及其点击监听
toolbar.inflateMenu(R.menu.menu_mainactivity);
toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
String result = "";
switch (item.getItemId()) {
case R.id.ac_toolbar_copy:
result = "Copy";
startActivity(new Intent(MainActivity.this, MainActivity.class));
//设置切换动画,从右边进入,左边退出
overridePendingTransition(R.anim.in_from_right, R.anim.out_to_left);
break;
case R.id.ac_toolbar_cut:
result = "Cut";
break;
case R.id.ac_toolbar_del:
result = "Del";
break;
case R.id.ac_toolbar_edit:
result = "Edit";
break;
case R.id.ac_toolbar_email:
result = "Email";
break;
}
Toast.makeText(MainActivity.this, result, Toast.LENGTH_SHORT).show();
return true;
}
});
tabLayout= (TabLayout) findViewById(R.id.tab);
tabLayout.setOverScrollMode(View.OVER_SCROLL_NEVER);
tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
TabLayout.Tab tab1=tabLayout.newTab().setText("首页");
tabLayout.addTab(tab1);
TabLayout.Tab tab2=tabLayout.newTab().setText("新闻");
tabLayout.addTab(tab2);
TabLayout.Tab tab3=tabLayout.newTab().setText("国际");
tabLayout.addTab(tab3);
TabLayout.Tab tab4=tabLayout.newTab().setText("国内");
tabLayout.addTab(tab4);
TabLayout.Tab tab5=tabLayout.newTab().setText("军事");
tabLayout.addTab(tab5);
TabLayout.Tab tab6=tabLayout.newTab().setText("娱乐");
tabLayout.addTab(tab6);
TabLayout.Tab tab7=tabLayout.newTab().setText("互联网+");
tabLayout.addTab(tab7);
TabLayout.Tab tab8 = tabLayout.newTab().setText("教育");
tabLayout.addTab(tab8);
tabLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, MainActivity.class));
overridePendingTransition(R.anim.in_from_right, R.anim.out_to_left);
}
});
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/main_root"
tools:context=".MainActivity"
android:orientation="vertical"> <android.support.v7.widget.Toolbar
android:id="@+id/toolbar_mainactivity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
app:popupTheme="@style/PopupMenu"
>
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="@+id/tab"
android:layout_below="@id/toolbar_mainactivity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabIndicatorColor="@color/colorAccent"
app:tabSelectedTextColor="@color/tab_select_color"
app:tabTextColor="@color/tab_unselect_color"
/>
</RelativeLayout>
上一篇:开源工具DbUtils的使用(数据库的增删改查)


下一篇:oracle-rman-3