TabHost的应用(上)------第三日
来源:互联网 发布:数控拉料器怎么编程 编辑:程序博客网 时间:2024/04/29 20:21
今天回来的太晚了,晚上去K歌了。发现现在生活太萎靡了,虽然没有烂醉,但是也嗨的嗓子不舒服啊。好了不啰嗦了,直接上代码。2013年2月26日23:46:50
今晚的TabHost只能贴出部分代码了,因为我还没有写完成。这个分成两部分写吧。
TabHost主activity:MainActivity,里面包含了两个ActivityGroup,分别为OneGroupActivity和TwoActivity;另外OneGroupActivity里面包含里两个activity。
MainActivity.java
package com.lianjiao.sport.activity;import android.annotation.SuppressLint;import android.app.AlertDialog;import android.app.TabActivity;import android.content.DialogInterface;import android.content.Intent;import android.os.Bundle;import android.os.StrictMode;import android.view.View;import android.view.Window;import android.widget.TabHost;import android.widget.TabHost.OnTabChangeListener;import android.widget.TabHost.TabSpec;import android.widget.TextView;import com.lianjiao.sport.R;import com.lianjiao.sport.activity.tabHostActivity.OneGroupActivity;import com.lianjiao.sport.activity.tabHostActivity.TwoGroupActivity;@SuppressWarnings("deprecation")public class MainActivity extends TabActivity {private TabHost m_tabHost;@SuppressLint("NewApi")@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState); StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() .detectDiskReads() .detectDiskWrites() .detectAll() // or .detectAll() for all detectable problems .penaltyLog() .build()); StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() .detectLeakedSqlLiteObjects() .detectLeakedClosableObjects() .penaltyLog() .penaltyDeath() .build());//隐去标题栏(应用程序的名字) this.requestWindowFeature(Window.FEATURE_NO_TITLE);setContentView(R.layout.activity_main);com.lianjiao.sport.activity.GlobalVariable.context=this; //getTabHost返回的TabHost用于装载tabs m_tabHost= getTabHost(); //addtabs,这里用于添加具体的Tabs,并用Tab触发相应的Activity addOneTab(); addTwoTab(); //初始化设置一次标签背景 updateTabBackground(m_tabHost); // m_tabHost.setCurrentTab(1);//0-3 m_tabHost.setOnTabChangedListener(new OnTabChangeListener() {public void onTabChanged(String tabId) { updateTabBackground(m_tabHost);} }); //选择时背景更改。 } public TabHost getM_tabHost() {return m_tabHost;}public void setM_tabHost(TabHost m_tabHost) {this.m_tabHost = m_tabHost;} @Overridepublic void finish() { // 确认对话框 //System.out.println("退出程序!!!!!"); final AlertDialog isExit = new AlertDialog.Builder(this).create(); // 对话框标题 isExit.setTitle(R.string.sys_info); // 对话框消息 isExit.setMessage(this.getString(R.string.is_exit)); // 实例化对话框上的按钮点击事件监听 DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { switch (which) { case AlertDialog.BUTTON1:// "确认"按钮退出程序 System.exit(0); break; case AlertDialog.BUTTON2:// "取消"第二个按钮取消对话框 isExit.cancel(); break; default: break; } } }; // 注册监听 isExit.setButton(this.getString(R.string.ok), listener); isExit.setButton2(this.getString(R.string.cancle), listener); // 显示对话框 isExit.show(); }/** * 更新Tab标签的背景图 * @param tabHost */ private void updateTabBackground(final TabHost tabHost) { for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) { View vvv = tabHost.getTabWidget().getChildAt(i); vvv.setMinimumWidth(500); if (tabHost.getCurrentTab() == i) { //选中后的背景 vvv.setBackgroundDrawable(getResources().getDrawable(R.drawable.nav_button_fourse)); } else { //非选择的背景 vvv.setBackgroundDrawable(getResources().getDrawable(R.drawable.nav_button_unfourse)); } } } public void addOneTab(){ Intent intent = new Intent(); intent.setClass(MainActivity.this,OneGroupActivity.class); TabSpec spec = m_tabHost.newTabSpec("One"); TextView t1 = new TextView(this); t1.setText(R.string.one); t1.setTextSize(30); t1.setPadding(10, 10, 10, 10); spec.setIndicator(t1); //spec.setIndicator(getString(R.string.one),null); spec.setContent(intent); m_tabHost.addTab(spec); } public void addTwoTab(){ Intent intent = new Intent(); intent.setClass(MainActivity.this,TwoGroupActivity.class); TabSpec spec = m_tabHost.newTabSpec("Two"); TextView t2 = new TextView(this); t2.setText(R.string.two); t2.setTextSize(30); t2.setPadding(10, 10, 10, 10); spec.setIndicator(t2); spec.setContent(intent); m_tabHost.addTab(spec); } }
activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <TabHost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/tabhost" android:background="@drawable/tab_background" android:layout_width="fill_parent" android:layout_height="fill_parent"> <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <LinearLayout android:orientation="horizontal" android:background="@drawable/nav_background" android:layout_width="fill_parent" android:layout_height="wrap_content"> <Button android:id="@+id/cancle" android:background="@drawable/nav_buttonbackground" android:layout_width="80dp" android:layout_height="wrap_content" android:layout_marginTop="5dp" android:layout_marginLeft="20dp" android:text="weizhi" /> <TabWidget android:id="@android:id/tabs" android:layout_width="300dp" android:layout_height="wrap_content" android:layout_marginLeft="350dp" android:paddingTop="2dip" > </TabWidget> <Button android:id="@+id/cancle1" android:background="@drawable/nav_buttonbackground" android:layout_width="80dp" android:layout_height="wrap_content" android:layout_marginTop="5dp" android:layout_marginLeft="400dp" android:text="lianjiao" /> </LinearLayout> <FrameLayoutandroid:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="0dip" android:layout_weight="1" /> </LinearLayout> </TabHost>
明天加个班把代码贴完,并贴出效果图吧。现在做的这些都是一些初步的框架,对于传感器的使用我还是比较薄弱的。最近也要加紧练习了。现在等于说完全是在整理老代码,说来也怪,最近每天晚上都有一些事情,耽搁了。万物安!
- TabHost的应用(上)------第三日
- TabHost的应用(中)-------(第四日)
- Tabhost的基本应用
- tabhost的应用
- TabHost的相关应用
- Android中TabHost的应用
- android布局学习(一):tabHost的应用
- TabHost应用
- TabHost应用
- [7月1日]LAMP兄弟连在线讲堂 -- PHP的模板应用Smarty(上)
- SNS应用开发者日:第三方应用的现状与前景
- 简单的android选项卡Tab菜单TabHost(一)同一Activity上实现
- tabhost的使用(1)
- tabHost研究二 ,android应用中,大部分的软件都会采用把按钮放在底部显示(tabHost)。利用三个Radiobutton嵌套在RadioGroup 。
- 第三日
- 第三日
- 第三日
- 第三课-函数的升级(上)
- 进入黑马day3-xml三种解析方法比较
- 进入黑马day3-HTTP协议与tomcat协议
- 奇数在左偶数在右
- jquery按钮控制text文本框商品数量增加或减少
- IOS中Json解析的四种方法
- TabHost的应用(上)------第三日
- Java中基本数据类型和引用型数据类型的区别
- 2013-02-26 新学期的 第一天~~~~~
- GDB调试core文件样例(如何定位Segment fault)
- Qemu 联网问题
- Oracle查询时做条件判断
- [iPhone初级]IOS自带NSXMLParser对xml文件的解析
- ATL问题集
- 将16进制数据转换为字符并打印