TabHost的使用

public class HomeActivity extends ActivityBase {
	private final static String TAG = "HomeActivity";
	private FragmentTabHost tabHost;
	// private TabWidget tabWidget;
	private int currot = 0;
	private ArrayList<Integer> tabimages;
	private ArrayList<String> tabtexts;
	private ArrayList<Class> fragments;
	private Context context;
	private ArrayList<View> tabViews;

	private static final int STUDYTAB = 2;
	private boolean newsCenterFlag = true;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.xxx);
		context = this;
		initDatas();
	}

	private void initDatas() {

		tabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
		tabHost.setup(context, getSupportFragmentManager(),
				android.R.id.tabcontent);

		tabtexts = new ArrayList<String>();
		tabtexts.add("item 1");
		tabtexts.add("item 2");
		tabtexts.add("item 3");
		tabtexts.add("item 4");
		tabtexts.add("item 5");

		tabimages = new ArrayList<Integer>();
		tabimages.add(R.drawable.tablehost_icon1);
		tabimages.add(R.drawable.tablehost_icon2);
		tabimages.add(R.drawable.tablehost_icon3);
		tabimages.add(R.drawable.tablehost_icon4);
		tabimages.add(R.drawable.tablehost_icon5);

		tabViews = new ArrayList<View>();
		View tabView1 = getLayoutInflater().inflate(R.layout.tab_widget_layout, null);
		View tabView2 = getLayoutInflater().inflate(R.layout.tab_widget_layout, null);
		View tabView3 = getLayoutInflater().inflate(R.layout.tab_widget_layout, null);
		View tabView4 = getLayoutInflater().inflate(R.layout.tab_widget_layout, null);
		View tabView5 = getLayoutInflater().inflate(R.layout.tab_widget_layout, null);
		((TextView) tabView1.findViewById(R.id.tab_text)).setText(tabtexts.get(0));
		((TextView) tabView2.findViewById(R.id.tab_text)).setText(tabtexts.get(1));
		((TextView) tabView3.findViewById(R.id.tab_text)).setText(tabtexts.get(2));
		((TextView) tabView4.findViewById(R.id.tab_text)).setText(tabtexts.get(3));
		((TextView) tabView5.findViewById(R.id.tab_text)).setText(tabtexts.get(4));
		((ImageView) tabView1.findViewById(R.id.tab_image)).setImageDrawable(getResources().getDrawable(tabimages.get(0)));
		((ImageView) tabView2.findViewById(R.id.tab_image)).setImageDrawable(getResources().getDrawable(tabimages.get(1)));
		((ImageView) tabView3.findViewById(R.id.tab_image)).setImageDrawable(getResources().getDrawable(tabimages.get(2)));
		((ImageView) tabView4.findViewById(R.id.tab_image)).setImageDrawable(getResources().getDrawable(tabimages.get(3)));
		((ImageView) tabView5.findViewById(R.id.tab_image)).setImageDrawable(getResources().getDrawable(tabimages.get(4)));
		tabViews.add(tabView1);
		tabViews.add(tabView2);
		tabViews.add(tabView3);
		tabViews.add(tabView4);
		tabViews.add(tabView5);

		fragments = new ArrayList<Class>();
		fragments.add(MyHomeFragment.class);
		fragments.add(PositionFragment.class);
		fragments.add(MicrostudyFragment.class);
		fragments.add(ChatBarHomeFragment.class);
		fragments.add(SystemSetFragment.class);

		tabHost.addTab(tabHost.newTabSpec("myhome").setIndicator(tabViews.get(0)), fragments.get(0), null);
		tabHost.addTab(tabHost.newTabSpec("home").setIndicator(tabViews.get(1)), fragments.get(1), null);
		tabHost.addTab(tabHost.newTabSpec("position").setIndicator(tabViews.get(2)), fragments.get(2), null);
		tabHost.addTab(tabHost.newTabSpec("study").setIndicator(tabViews.get(3)), fragments.get(3), null);
		tabHost.addTab(tabHost.newTabSpec("more").setIndicator(tabViews.get(4)), fragments.get(4), null);
		tabHost.setCurrentTab(0);
	}

	public FragmentTabHost getTabHost() {
		return this.tabHost;
	}

	public void currentTabHost(int index) {
		if (tabHost != null) {
			tabHost.setCurrentTab(index);
		}
	}

	@Override
	protected void onResume() {
		context = this;
		super.onResume();
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {

			if (tabHost.getCurrentTab() == STUDYTAB && MicrostudyFragment.type == MicrostudyFragment.SEACHTYPE) {
				MicrostudyFragment.type = 0;
				MicrostudyFragment.setScroll();
				if (MicrostudyFragment.list != null) {
					MicrostudyFragment.adapter.getDataList().clear();
					MicrostudyFragment.adapter.getDataList().addAll(MicrostudyFragment.list);
					MicrostudyFragment.adapter.notifyDataSetChanged();
					MicrostudyFragment.hideBackButton();
				}
				return true;
			} else {
				Dialog dialog = new AlertDialog.Builder(HomeActivity.this)
						.setMessage("确认退出?")
						.setPositiveButton("确定",
								new DialogInterface.OnClickListener() {
									@Override
									public void onClick(DialogInterface dialog, int which) {
										// 注销notify
										NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
										mNotificationManager.cancel(CustomNotify
												.getInstanct(context).ints[0]);
										mNotificationManager.cancel(CustomNotify
												.getInstanct(context).ints[1]);
										mNotificationManager.cancel(CustomNotify
												.getInstanct(context).ints[2]);
										Intent intent = new Intent(
												Intent.ACTION_MAIN);
										intent.addCategory(Intent.CATEGORY_HOME);
										intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
										startActivity(intent);
										HomeActivity.this.exitApp();
									}
								})
						.setNegativeButton("取消",
								new DialogInterface.OnClickListener() {
									public void onClick(DialogInterface dialog, int whichButton) {
										// 点击"取消"按钮
									}
								}).create();// 创建
				// 显示对话框
				dialog.show();
			}

		} else if (keyCode == KeyEvent.KEYCODE_MENU) {
			return true;
		}
		return super.onKeyDown(keyCode, event);
	}

}



=======================下面跟上面无关=====================

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">


    <FrameLayout
        android:id="@+id/main_container"
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="1"/>


    <View
        android:layout_width="match_parent"
        android:layout_height="1.0dip"
        android:background="#"/>
    <RadioGroup
        android:id="@+id/radioGroup"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0"
        android:layout_alignParentBottom="true"
        android:background="#FFFFFF"
        android:orientation="horizontal">

        <RadioButton
            android:id="@+id/rb_chat"
            android:checked="true"
            android:text="首页"
            android:drawableTop="@mipmap/ic_launcher"
            style="@style/mian_bottom_button_style" />

        <RadioButton
            android:id="@+id/rb_contacts"
            android:text="关注"
            android:drawableTop="@mipmap/ic_launcher"
            style="@style/mian_bottom_button_style"/>

        <RadioButton
            android:id="@+id/rb_discovery"
            android:text="我"
            android:drawableTop="@mipmap/ic_launcher"
            style="@style/mian_bottom_button_style" />
    <!--  android:drawableTop="@drawable/rb_chat_selector"-->
    </RadioGroup>





 

                
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值