android 第一个界面 选项卡加toolbar
来源:互联网 发布:武汉淘宝外包 编辑:程序博客网 时间:2024/06/05 03:05
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; } }); }
效果图
第一个有点小样子的,数据是死的,乱写的。目前菜鸟级别。
基本不太明白自己写的什么
0 0
- android 第一个界面 选项卡加toolbar
- android 选项卡界面
- 第一个 android 的界面程序
- 进入第一个Android应用界面
- 解决android安卓TabHost默认进入第一个选项卡onCreate的问题.顺序问题
- 第一个UI界面
- 第一个留言板界面
- 选项卡加定时器
- ANDROID第一个UI界面学---登录到对话框
- 动手学Android之三——第一个界面
- 使用kotlin编写第一个Android应用界面
- 界面组件:选项卡
- Android 多个Activity选项卡实现
- 第一个Java界面程序
- IOS第一个界面应用
- [Android界面0]图标选项卡效果,用TabActivity实现
- Android UI设计 选项卡实现界面切换
- Android程序——使用选项卡实现界面切换
- js delete 用法(删除对象属性及变量)
- response.setHeader参数、用法的介绍
- 商城数据库设计--商品属性
- c语言程序设计流程图详解
- Get Jenkins job build queue length
- android 第一个界面 选项卡加toolbar
- Anddroid 物流查询快递查询
- 欢迎使用CSDN-markdown编辑器
- POJ2070 Filling Out the Team
- NameNode 高可用整体架构概述
- Mac OS X上安装和使用Homebrew和Homebrew Cask来进行软件安装管理
- Android基础_SharedPreferences
- iOS开发罗盘/指南针
- g++参数简介