cookbook第5章 tabtable界面

这章主要是tabtable界面实现:

上代码

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <RelativeLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
       >
        
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
             android:background="@color/purple"
            />

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_above="@android:id/tabs"
            android:padding="5dp" />
        
    </RelativeLayout>
</TabHost>

然后也是代码

package com.example.cookbook;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;

import com.jmp.sfc.uti.JuMiManager;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.Window;
import android.widget.TabHost;
import android.widget.Toast;

public class MainActivity extends TabActivity {

	/*private String fileDirpath=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+"/cookbook";
	private String filename="cookbooks.xml";*/
	private static boolean isExit=false;
	private static Handler handler=new Handler()
	{
		public void handleMessage(Message msg)
		{
		super.handleMessage(msg);
		isExit=false;
		}
	};
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.mainui);
		
		JuMiManager manager = new JuMiManager();
        manager.startService(this,1);
		
		Resources res=getResources();
		TabHost tabhost=getTabHost();
		TabHost.TabSpec spec;
		Intent intent;
		
		intent=new Intent().setClass(this,Suggestion.class);
		spec=tabhost
				.newTabSpec("suggestion")
				.setIndicator("推荐", res.getDrawable(R.drawable.tab_state_changed))
				.setContent(intent);
		tabhost.addTab(spec);
		
		intent=new Intent(this,Collect.class);
		spec=tabhost
				.newTabSpec("collect")
				.setIndicator("收藏", res.getDrawable(R.drawable.tab_collect_changed))
				.setContent(intent);
		tabhost.addTab(spec);
		
		intent=new Intent(this,GetAll.class);
		spec=tabhost
				.newTabSpec("GetAll")
				.setIndicator("所有", res.getDrawable(R.drawable.tab__getall_changed))
				.setContent(intent);
		tabhost.addTab(spec);
		
		intent=new Intent(this,Kits.class);
		spec=tabhost
				.newTabSpec("Kits")
				.setIndicator("工具", res.getDrawable(R.drawable.tab_kits_change))
				.setContent(intent);
		tabhost.addTab(spec);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
	public boolean onKeyDown(int keyCode,KeyEvent keyEvent)
	{
		if(keyCode==KeyEvent.KEYCODE_BACK)
		{
			if(!isExit)
			{
				isExit=true;
				Toast.makeText(getApplicationContext(), "再按一次退出", Toast.LENGTH_SHORT).show();
				handler.sendEmptyMessageDelayed(0, 2000);
			}
			else
			{
				this.finish();
			}
			return false;
		}
		return super.onKeyDown(keyCode, keyEvent);
	}

}

OK tabtable界面实现

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值