Tab(选项卡)界面

界面效果
[img]http://dl.iteye.com/upload/attachment/0073/5491/8888e99a-ba18-3f1b-bc1e-b592d33f9c30.png[/img]

package com.kaka.kkpy.activity;

import com.kaka.kkpy.activity.R;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;
import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.TabHost;

public class MainTabActivity extends TabActivity implements OnCheckedChangeListener{

private TabHost mTabHost;
private Intent mAIntent;
private Intent mBIntent;
private Intent mCIntent;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.maintabs);

this.mAIntent = new Intent(this,CreateCardActivity.class);
this.mBIntent = new Intent(this,CaptureA.class);
//this.mCIntent = new Intent(this,CActivity.class);

((RadioButton) findViewById(R.id.radio_button0))
.setOnCheckedChangeListener(this);
((RadioButton) findViewById(R.id.radio_button1))
.setOnCheckedChangeListener(this);
((RadioButton) findViewById(R.id.radio_button2))
.setOnCheckedChangeListener(this);

setupIntent();
}

@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
switch (buttonView.getId()) {
case R.id.radio_button0:
this.mTabHost.setCurrentTabByTag("A_TAB");
break;
case R.id.radio_button1:
this.mTabHost.setCurrentTabByTag("B_TAB");
break;
case R.id.radio_button2:
this.mTabHost.setCurrentTabByTag("C_TAB");
break;
}
}

}

private void setupIntent() {
this.mTabHost = getTabHost();
TabHost localTabHost = this.mTabHost;

localTabHost.addTab(buildTabSpec("A_TAB", R.string.main_home,
R.drawable.icon, this.mAIntent));

localTabHost.addTab(buildTabSpec("B_TAB", R.string.scan,
R.drawable.icon, this.mBIntent));

localTabHost.addTab(buildTabSpec("C_TAB",
R.string.my, R.drawable.icon,
this.mCIntent));

}

private TabHost.TabSpec buildTabSpec(String tag, int resLabel, int resIcon,
final Intent content) {
return this.mTabHost.newTabSpec(tag).setIndicator(getString(resLabel),
getResources().getDrawable(resIcon)).setContent(content);
}
}


layout代码

<?xml version="1.0" encoding="UTF-8"?>
<TabHost android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="0.0dip"
android:layout_weight="1.0" />
<TabWidget
android:id="@android:id/tabs"
android:visibility="gone"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.0" />
<RadioGroup
android:gravity="center_vertical"
android:layout_gravity="bottom"
android:orientation="horizontal"
android:id="@id/main_radio"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<RadioButton
android:id="@id/radio_button0"
android:layout_marginTop="2.0dip"
android:text="@string/main_home"
style="@style/main_tab_bottom" />
<RadioButton
android:id="@id/radio_button1"
android:layout_marginTop="2.0dip"
android:text="@string/scan"
style="@style/main_tab_bottom" />
<RadioButton
android:id="@id/radio_button2"
android:layout_marginTop="2.0dip"
android:text="@string/my"
style="@style/main_tab_bottom" />
</RadioGroup>
</LinearLayout>
</TabHost>



styles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="main_tab_bottom">
<item name="android:textSize">@dimen/bottom_tab_font_size</item>
<item name="android:textColor">#ffffffff</item>
<item name="android:ellipsize">marquee</item>
<item name="android:gravity">center_horizontal</item>
<item name="android:background">@drawable/home_btn_bg</item>
<item name="android:paddingTop">@dimen/bottom_tab_padding_up</item>
<item name="android:paddingBottom">2.0dip</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_marginBottom">2.0dip</item>
<item name="android:button">@null</item>
<item name="android:singleLine">true</item>
<item name="android:drawablePadding">@dimen/bottom_tab_padding_drawable</item>
<item name="android:layout_weight">1.0</item>
</style>

</resources>


<?xml version="1.0" encoding="UTF-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:state_enabled="true" android:state_pressed="false" android:drawable="@drawable/icon" />
<item android:state_enabled="true" android:state_pressed="true" android:drawable="@drawable/icon" />
<item android:state_enabled="true" android:state_checked="true" android:drawable="@drawable/icon" />
<item android:drawable="@drawable/icon" />
</selector>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值