toolbar.xml
</pre><pre style="font-family: 宋体; font-size: 12pt; background-color: rgb(255, 255, 255);"><span style="font-style:italic;"><?</span><span style="color:#0000ff;"><strong>xml version=</strong></span><span style="color:#008000;"><strong>"1.0" </strong></span><span style="color:#0000ff;"><strong>encoding=</strong></span><span style="color:#008000;"><strong>"utf-8"</strong></span><span style="font-style:italic;">?> </span><<span style="color:#000080;"><strong>LinearLayout </strong></span><span style="color:#0000ff;"><strong>xmlns:</strong></span><span style="color:#660e7a;"><strong>android</strong></span><span style="color:#0000ff;"><strong>=</strong></span><span style="color:#008000;"><strong>"http://schemas.android.com/apk/res/android" </strong></span><span style="color:#008000;"><strong> </strong></span><span style="color:#660e7a;"><strong>android</strong></span><span style="color:#0000ff;"><strong>:id=</strong></span><span style="color:#008000;"><strong>"@+id/FrameLayout01" </strong></span><span style="color:#008000;"><strong> </strong></span><span style="color:#660e7a;"><strong>android</strong></span><span style="color:#0000ff;"><strong>:layout_width=</strong></span><span style="color:#008000;"><strong>"match_parent" </strong></span><span style="color:#008000;"><strong> </strong></span><span style="color:#660e7a;"><strong>android</strong></span><span style="color:#0000ff;"><strong>:layout_height=</strong></span><span style="color:#008000;"><strong>"match_parent" </strong></span><span style="color:#008000;"><strong> </strong></span><span style="color:#660e7a;"><strong>android</strong></span><span style="color:#0000ff;"><strong>:orientation=</strong></span><span style="color:#008000;"><strong>"vertical"</strong></span>> <<span style="color:#000080;"><strong>include </strong></span><span style="color:#0000ff;"><strong>layout=</strong></span><span style="color:#008000;"><strong>"@layout/toolbar" </strong></span>/> <<span style="color:#000080;"><strong>TabHost </strong></span><span style="color:#0000ff;"><strong>xmlns:</strong></span><span style="color:#660e7a;"><strong>android</strong></span><span style="color:#0000ff;"><strong>=</strong></span><span style="color:#008000;"><strong>"http://schemas.android.com/apk/res/android" </strong></span><span style="color:#008000;"><strong> </strong></span><span style="color:#660e7a;"><strong>android</strong></span><span style="color:#0000ff;"><strong>:id=</strong></span><span style="color:#008000;"><strong>"@android:id/tabhost" </strong></span><span style="color:#008000;"><strong> </strong></span><span style="color:#660e7a;"><strong>android</strong></span><span style="color:#0000ff;"><strong>:layout_width=</strong></span><span style="color:#008000;"><strong>"match_parent" </strong></span><span style="color:#008000;"><strong> </strong></span><span style="color:#660e7a;"><strong>android</strong></span><span style="color:#0000ff;"><strong>:layout_height=</strong></span><span style="color:#008000;"><strong>"match_parent"</strong></span>> <<span style="color:#000080;"><strong>LinearLayout </strong></span><span style="color:#000080;"><strong> </strong></span><span style="color:#660e7a;"><strong>android</strong></span><span style="color:#0000ff;"><strong>:layout_width=</strong></span><span style="color:#008000;"><strong>"match_parent" </strong></span><span style="color:#008000;"><strong> </strong></span><span style="color:#660e7a;"><strong>android</strong></span><span style="color:#0000ff;"><strong>:layout_height=</strong></span><span style="color:#008000;"><strong>"match_parent" </strong></span><span style="color:#008000;"><strong> </strong></span><span style="color:#660e7a;"><strong>android</strong></span><span style="color:#0000ff;"><strong>:orientation=</strong></span><span style="color:#008000;"><strong>"vertical"</strong></span>> <<span style="color:#000080;"><strong>TabWidget </strong></span><span style="color:#000080;"><strong> </strong></span><span style="color:#660e7a;"><strong>android</strong></span><span style="color:#0000ff;"><strong>:id=</strong></span><span style="color:#008000;"><strong>"@android:id/tabs" </strong></span><span style="color:#008000;"><strong> </strong></span><span style="color:#660e7a;"><strong>android</strong></span><span style="color:#0000ff;"><strong>:layout_width=</strong></span><span style="color:#008000;"><strong>"match_parent" </strong></span><span style="color:#008000;"><strong> </strong></span><span style="color:#660e7a;"><strong>android</strong></span><span style="color:#0000ff;"><strong>:layout_height=</strong></span><span style="color:#008000;"><strong>"wrap_content" </strong></span>/> <<span style="color:#000080;"><strong>FrameLayout </strong></span><span style="color:#000080;"><strong> </strong></span><span style="color:#660e7a;"><strong>android</strong></span><span style="color:#0000ff;"><strong>:id=</strong></span><span style="color:#008000;"><strong>"@android:id/tabcontent" </strong></span><span style="color:#008000;"><strong> </strong></span><span style="color:#660e7a;"><strong>android</strong></span><span style="color:#0000ff;"><strong>:layout_width=</strong></span><span style="color:#008000;"><strong>"match_parent" </strong></span><span style="color:#008000;"><strong> </strong></span><span style="color:#660e7a;"><strong>android</strong></span><span style="color:#0000ff;"><strong>:layout_height=</strong></span><span style="color:#008000;"><strong>"match_parent"</strong></span>></<span style="color:#000080;"><strong>FrameLayout</strong></span>> </<span style="color:#000080;"><strong>LinearLayout</strong></span>> </<span style="color:#000080;"><strong>TabHost</strong></span>> </<span style="color:#000080;"><strong>LinearLayout</strong></span>>
main_segtab.xml
<resources> <style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar"> <!-- toolbar(actionbar)颜色 --> <item name="colorPrimary">#4876FF</item> <!-- 状态栏颜色 --> <item name="colorPrimaryDark">#3A5FCD</item> <!-- 窗口的背景颜色 --> <item name="android:windowBackground">@android:color/white</item> <!-- SearchView --> <item name="searchViewStyle">@style/MySearchViewStyle</item> </style> <style name="AppTheme" parent="@style/AppBaseTheme"></style> <style name="MySearchViewStyle" parent="Widget.AppCompat.SearchView"> </style> </resources>
styles.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <style name="AppTheme" parent="@style/AppBaseTheme"> <!-- 底部导航栏颜色 --> <item name="android:navigationBarColor">#4876FF</item> </style> </resources>
styles/v21.xml
mainActivity.java
public class MainActivity extends AppCompatActivity { private Toolbar toolbar; private TabHost tabHost; ActionBarDrawerToggle mDrawerToggle; DrawerLayout mDrawerLayout; void init(){ } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_segtab); initToolBar(); initTabHost(); } public void initTabHost(){ tabHost=(TabHost)findViewById(android.R.id.tabhost); tabHost.setup(); LayoutInflater inflater=LayoutInflater.from(this); inflater.inflate(R.layout.tab1,tabHost.getTabContentView()); inflater.inflate(R.layout.tab2,tabHost.getTabContentView()); inflater.inflate(R.layout.tab3, tabHost.getTabContentView()); //添加标签页 tabHost.addTab(tabHost.newTabSpec("tab01").setIndicator("推荐").setContent(R.id.LinearLayout01)); tabHost.addTab(tabHost.newTabSpec("tab02").setIndicator("订阅").setContent(R.id.LinearLayout02)); tabHost.addTab(tabHost.newTabSpec("tab03").setIndicator("发现").setContent(R.id.LinearLayout03)); } public void initToolBar(){ toolbar = (Toolbar)findViewById(R.id.toolbar); toolbar.setTitle("标题"); setSupportActionBar(toolbar); //菜单监听 toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case R.id.ab_search: Toast.makeText(MainActivity.this, "action_search", Toast.LENGTH_SHORT).show(); break; case R.id.action_share: Toast.makeText(MainActivity.this, "action_share", Toast.LENGTH_SHORT).show(); break; } return true; } }); }
效果图
第一个有点小样子的,数据是死的,乱写的。目前菜鸟级别。
基本不太明白自己写的什么