这章主要是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界面实现