tabhost(tabweight自定义)
2014-06-12 15:34
134 查看
main.call
public class MainActivity extends TabActivity { private TabHost mTabHost; private TextView tv; private TabWidget tabWidget; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // mTabHost=(TabHost)this.findViewById(android.R.id.tabhost); mTabHost = getTabHost(); // mTabHost.setup(); Intent intent1 = new Intent(this,OneActivity.class); createTab("公共聊天室",intent1); Intent intent2 = new Intent(this,TwoActivity.class); createTab("周边",intent2); Intent intent3 = new Intent(this,OneActivity.class); createTab("历史",intent3); mTabHost.setCurrentTab(1); tabWidget = mTabHost.getTabWidget(); mTabHost.setOnTabChangedListener(new OnTabChangeListener(){ @Override public void onTabChanged(String tabId) { for (int i =0; i < tabWidget.getChildCount(); i++) { View vvv = tabWidget.getChildAt(i); if(mTabHost.getCurrentTab()==i){ if(tabId=="公共聊天室"){ Toast.makeText(MainActivity.this, "公共聊天室", 1).show(); }if(tabId=="周边"){ Toast.makeText(MainActivity.this, "周边", 1).show(); }if(tabId=="历史"){ Toast.makeText(MainActivity.this, "历史", 1).show(); } } } }}); } private void createTab(String text, Intent intent1) { mTabHost.addTab(mTabHost.newTabSpec(text) .setIndicator(createTabView(text)) //创建自定义的tabweigth .setContent(intent1)); } private View createTabView(String text) { View view = LayoutInflater.from(this).inflate(R.layout.tab_indicator, null); tv = (TextView) view.findViewById(R.id.tv_tab); tv.setText(text); return view; } }tab_indicator.xml 自定义的tabweight界面
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="fill_parent" android:layout_width="fill_parent" android:orientation="vertical" android:gravity="center" android:theme="@android:style/Theme.NoTitleBar" android:background="@drawable/chat_tab_selector"> <TextView android:id="@+id/tv_tab" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="tab1" /> </LinearLayout>chat_tab_selector.xml 点击tabweiget的背景色变化
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android" ><itemandroid:state_focused = "true"android:drawable = "@drawable/topbar_bg_down" /><itemandroid:state_selected = "true"android:drawable = "@drawable/topbar_bg_down" /><itemandroid:state_pressed = "true"android:drawable = "@drawable/topbar_bg_down" /><item android:drawable = "@drawable/topbar_background" /></selector>
相关文章推荐
- 自定义Tabhost里的TabWidget布局
- Android 如何自定义FragmentTabHost中某一个Tab的点击效果
- 自定义TabHost,TabWidget样式
- 如何 TabHostFragment自定义 tab键(indicator)
- 自定义tabhost实现tab切换动画
- 自定义TabHost,TabWidget样式 .
- 自定义TabHost,TabWidget样式 .
- Android自定义TabWeight (修改样式)
- android学习笔记《三》:TabHost中自定义TabWidget
- 自定义Tabhost里的TabWidget布局
- 自定义TabHost,TabWidget样式 .
- 如何自定义FragmentTabHost中某一个Tab的点击效果
- android自定义tabhost,tabcontent用intent获得
- Android程序开发之自定义设置TabHost,TabWidget样式
- Android中自定义tabhost的TAB页面被选中时TAB底部的颜色
- 自定义TabHost,TabWidget样式 .
- android自定义tabhost,tabcontent用intent获得
- 自定义标题背景的TabControl(转贴)
- TabTopUnderLineLayout【自定义顶部选项卡(带下划线)】
- Android游戏开发系统控件-TabSpec与TabHost