情景模式(Tab切换组件)

情景模式截图

Layout布局代码:

activity_main.xml代码

不用编写

activity1.xml代码

<RadioButton
        android:id="@+id/r2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/r4"
        android:layout_below="@+id/r3"
        android:layout_marginTop="40dp"
        android:text="振动" />

    <RadioButton
        android:id="@+id/r1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/r2"
        android:layout_alignParentTop="true"
        android:layout_marginTop="40dp"
        android:text="铃声和振动" />

    <RadioButton
        android:id="@+id/r3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/r2"
        android:layout_below="@+id/r1"
        android:layout_marginTop="40dp"
        android:text="铃声" />

    <RadioButton
        android:id="@+id/r4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/r2"
        android:layout_marginTop="40dp"
        android:text="静音" />
  

activity2.xml代码

 <TextView
        android:id="@+id/t1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="设定时间:"/>

    <TimePicker
        android:id="@+id/timePicker1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <RadioButton
        android:id="@+id/r2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="30dp"
        android:text="振动" />

    <RadioButton
        android:id="@+id/r1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/r2"
        android:layout_alignParentTop="true"
        android:layout_marginTop="40dp"
        android:text="铃声和振动" />

    <RadioButton
        android:id="@+id/r3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="40dp"
        android:text="铃声" />

    <RadioButton
        android:id="@+id/r4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="40dp"
        android:text="静音" />

 

activity3.xml代码

<TableRow
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    <TextView
        android:id="@+id/t1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
         android:layout_marginTop="20dp"
        android:text="声音模式"/>
     <ImageButton
        android:id="@+id/imageButton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher" />
</TableRow>

    <TextView
        android:id="@+id/t2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:text="声音音量" />

   <SeekBar
       android:id="@+id/seekBar1"
       android:layout_width="match_parent"
       android:layout_height="wrap_content" />

   <TableRow
       android:layout_height="wrap_content"
       android:layout_width="wrap_content"
       android:layout_gravity="center_vertical">

   <ImageButton
       android:id="@+id/imageButton3"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:src="@android:drawable/stat_sys_download" />
    <ImageButton
       android:id="@+id/imageButton2"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:src="@android:drawable/stat_sys_upload" />
    </TableRow>

 

主要代码:

MainActivity.java代码

public class MainActivity extends TabActivity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  //setContentView(R.layout.activity1);
  TabHost tabhost=getTabHost();
  getLayoutInflater().inflate(R.layout.activity_main, tabhost.getTabContentView());
  
  Intent tab1=new Intent();
  tab1.setClass(this,Activity1.class);
  TabHost.TabSpec tab01 = tabhost.newTabSpec("tab01")
    .setIndicator("普通情境模式").setContent(tab1);
  
  
  Intent tab2=new Intent();
  tab2.setClass(this,Activity2.class);
  TabHost.TabSpec tab02 = tabhost.newTabSpec("tab02")
    .setIndicator("定时情境模式").setContent(tab2);
  
   
    Intent tab3=new Intent();
    tab3.setClass(this, Activity3.class);
    TabHost.TabSpec tab03 = tabhost.newTabSpec("tab03")
   .setIndicator("自由情境模式").setContent(tab3);
}
 


 @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;
 }

}

 

Activity1.java

不用编写

 

Activity2.java

不用编写

 

Activity3.java

不用编写

 

赶快运行一下吧!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值