
<TabHost android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent" > <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <LinearLayout android:id="@+id/console_line_bottom" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <RadioGroup android:id="@+id/main_tab_group" android:background="@color/white" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <RadioButton android:id="@+id/rb_tab_useCabage" android:background="#00D4A0" android:padding="10dp" android:gravity="center_horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="2" android:checked="true" android:textSize="16sp" android:button="@null" android:text="消费" /> <RadioButton android:id="@+id/rb_tab_chongzhiCabage" android:padding="10dp" android:gravity="center_horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="2" android:button="@null" android:textSize="16sp" android:text="充值" /> </RadioGroup> </LinearLayout> <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:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="0.0" android:visibility="gone" /> </LinearLayout> </TabHost>
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364public class XiaoFeiWater extends TabActivity implements OnClickListener { TabHost tabHost; private RadioButton rb_tab_useCabage,rb_tab_chongzhiCabage; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.activity_xiaofei_water); initTab(); init(); } /** * 初始化数据 */ private void init() { rb_tab_useCabage = (RadioButton) findViewById(R.id.rb_tab_useCabage); rb_tab_chongzhiCabage = (RadioButton) findViewById(R.id.rb_tab_chongzhiCabage); rb_tab_useCabage.setOnClickListener(this); rb_tab_chongzhiCabage.setOnClickListener(this); } /** * 初始化Tab */ private void initTab() { tabHost=getTabHost(); tabHost.addTab(tabHost.newTabSpec("use").setIndicator("use") .setContent(new Intent(this, XiaoFeiCabageActivity.class))); tabHost.addTab(tabHost.newTabSpec("chongzhi").setIndicator("chongzhi") .setContent(new Intent(this, ChongZhiCabageActivity.class))); } /** * 点击事件 * @param v */ @Override public void onClick(View v) { switch (v.getId()) { case R.id.rb_tab_useCabage: tabHost.setCurrentTabByTag("use"); break; case R.id.rb_tab_chongzhiCabage: tabHost.setCurrentTabByTag("chongzhi"); break; default: break; } }
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455相关知识
Android 实现点击两个按钮,原地切换界面
Android 实现应用内语言切换(包括不重启应用方式)
Android Studio移动应用开发——onCreate、onSaveInstanceState、onRestoreInstance一个参数和两个参数
Android Studio实现简单的购物商城界面
用JavaScript实现图片切换功能:项目实例解析
揭秘Android系统中的小花界面:探索独特设计背后的秘密与挑战
Android百度地图 关于visibility=“gone”的奇葩问题
移动应用开发做登录界面(app手机登录界面)
Android入门开发经验
【朝花夕拾】Android性能篇之(六)Android进程管理机制
网址: Android 实现点击两个按钮,原地切换界面 https://m.huajiangbk.com/newsview2442058.html
| 上一篇: 一个反常识的真相:疯狂挣钱=不断 |
下一篇: 花椒树种植技术3要点,让您种植花 |