当前位置: 编程技术>移动开发
本页文章导读:
▪Ophone的开发的配备和安装 Ophone的开发的配置和安装
http://ophone8.com/thread-2668-1-1.html
......
▪ 监测是不是静音 监测是否静音
AudioManager am = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
switch (am.getRingerMode()) {
case AudioManager.RINGER_MODE_SILENT:
Log.i("MyApp","Silent mode");
break;
case AudioManager.RINGE.........
▪ TabActivity 分页 施用 TabActivity 分页 使用
TabActivity 分页[功能]TabActivity 即 该Activity 包括 若干个标签 每个标签里面包含一个Layout 就如同普通意义上的Activity 一样[原理]1. 每个标签的生成 都是借助于 TabHost2. 每.........
[1]Ophone的开发的配备和安装
来源: 互联网 发布时间: 2014-02-18
Ophone的开发的配置和安装
http://ophone8.com/thread-2668-1-1.html
http://ophone8.com/thread-2668-1-1.html
[2] 监测是不是静音
来源: 互联网 发布时间: 2014-02-18
监测是否静音
AudioManager am = (AudioManager)getSystemService(Context.AUDIO_SERVICE); switch (am.getRingerMode()) { case AudioManager.RINGER_MODE_SILENT: Log.i("MyApp","Silent mode"); break; case AudioManager.RINGER_MODE_VIBRATE: Log.i("MyApp","Vibrate mode"); break; case AudioManager.RINGER_MODE_NORMAL: Log.i("MyApp","Normal mode"); break; }
http://developer.android.com/intl/fr/reference/android/media/AudioManager.html#getRingerMode%28%29
[3] TabActivity 分页 施用
来源: 互联网 发布时间: 2014-02-18
TabActivity 分页 使用
TabActivity 分页
[功能]
TabActivity 即 该Activity 包括 若干个标签 每个标签里面包含一个Layout 就如同普通意义上的Activity 一样
[原理]
1. 每个标签的生成 都是借助于 TabHost
2. 每个标签里面都可以当做一个Activity 里面可以包含若干个View 比如 TextView ImageView 等等
3. 若干个标签是以 String 参数来区分的
[代码]
1. 得到TabHost实例
(其仅在TabActivity里面有效)
2. 创建一个标签
3. 标签里面如何布局
(且 item 必须 implements TabHost.TabContentFactory)
4. 自定义标签的布局
[所有代码]
TabActivity 分页
[功能]
TabActivity 即 该Activity 包括 若干个标签 每个标签里面包含一个Layout 就如同普通意义上的Activity 一样
[原理]
1. 每个标签的生成 都是借助于 TabHost
2. 每个标签里面都可以当做一个Activity 里面可以包含若干个View 比如 TextView ImageView 等等
3. 若干个标签是以 String 参数来区分的
[代码]
1. 得到TabHost实例
TabHost host = this.getTabHost();
(其仅在TabActivity里面有效)
2. 创建一个标签
public final static String TAB1 = "tab1"; host.addTab(host.newTabSpec(TAB1) .setIndicator("", getResources().getDrawable(R.drawable.beijing_001_mb5ucom)) .setContent(item));
3. 标签里面如何布局
host.setContent(item));
(且 item 必须 implements TabHost.TabContentFactory)
4. 自定义标签的布局
public class CustomTabs implements TabHost.TabContentFactory { Activity activity; LayoutInflater inflater; LinearLayout layout; public CustomTabs (Activity a) { activity = a; inflater = activity.getLayoutInflater(); } /** {@inheritDoc} */ public View createTabContent(String tag) { activity.setTitle(tag); return addCustomView(tag); } public View addCustomView(String id){ layout = new LinearLayout(activity); layout.setOrientation(LinearLayout.VERTICAL); if(id.equals(TAB1)){ ImageView iv = new ImageView(activity); iv.setImageResource(R.drawable.o); layout.addView(iv, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT)); } else if(id.equals(TAB2)){ EditText edit = new EditText(activity); layout.addView(edit, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); Button btn = new Button(activity); btn.setText("OK"); layout.addView(btn, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); RadioGroup group = new RadioGroup(activity); group.setOrientation(LinearLayout.HORIZONTAL); RadioButton radio1 = new RadioButton(activity); radio1.setText("Radio 1"); group.addView(radio1); RadioButton radio2 = new RadioButton(activity); radio2.setText("Radio 2"); group.addView(radio2); layout.addView(group, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); } else if(id.equals(TAB3)){ LinearLayout.LayoutParams param3 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT); layout.addView(inflater.inflate(R.layout.item_3, null),param3); } else if(id.equals(TAB4)){ LinearLayout.LayoutParams param4 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT); layout.addView(inflater.inflate(R.layout.item_4, null),param4); } else { TextView tv5 = new TextView(activity); tv5.setText("no resource aviable!"); tv5.setGravity(1); layout.addView(tv5, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT)); } return layout; } }
[所有代码]
public class CustomTabsUsage extends TabActivity { public final static String TAB1 = "tab1"; public final static String TAB2 = "tab2"; public final static String TAB3 = "tab3"; public final static String TAB4 = "tab4"; public final static String TAB5 = "tab5"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); CustomTabs item = new CustomTabs(this); TabHost host = this.getTabHost(); host.addTab(host.newTabSpec(TAB1) .setIndicator("", getResources().getDrawable(R.drawable.beijing_001_mb5ucom)) .setContent(item)); host.addTab(host.newTabSpec(TAB2) .setIndicator("",getResources().getDrawable(R.drawable.beijing_002_mb5ucom)) .setContent(item)); host.addTab(host.newTabSpec(TAB3) .setIndicator("",getResources().getDrawable(R.drawable.beijing_003_mb5ucom)) //.setIndicator("Tab3") .setContent(item)); host.addTab(host.newTabSpec(TAB4) .setIndicator("",getResources().getDrawable(R.drawable.beijing_004_mb5ucom)) .setContent(item)); host.addTab(host.newTabSpec(TAB5) .setIndicator("",getResources().getDrawable(R.drawable.beijing_005_mb5ucom)) .setContent(item)); host.setOnTabChangedListener(new OnTabChangeListener(){ @Override public void onTabChanged(String tabId) { // TODO Auto-generated method stub } }); } public class CustomTabs implements TabHost.TabContentFactory { Activity activity; LayoutInflater inflater; LinearLayout layout; public CustomTabs (Activity a) { activity = a; inflater = activity.getLayoutInflater(); } /** {@inheritDoc} */ public View createTabContent(String tag) { activity.setTitle(tag); return addCustomView(tag); } public View addCustomView(String id){ layout = new LinearLayout(activity); layout.setOrientation(LinearLayout.VERTICAL); if(id.equals(TAB1)){ ImageView iv = new ImageView(activity); iv.setImageResource(R.drawable.o); layout.addView(iv, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT)); } else if(id.equals(TAB2)){ EditText edit = new EditText(activity); layout.addView(edit, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); Button btn = new Button(activity); btn.setText("OK"); layout.addView(btn, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); RadioGroup group = new RadioGroup(activity); group.setOrientation(LinearLayout.HORIZONTAL); RadioButton radio1 = new RadioButton(activity); radio1.setText("Radio 1"); group.addView(radio1); RadioButton radio2 = new RadioButton(activity); radio2.setText("Radio 2"); group.addView(radio2); layout.addView(group, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); } else if(id.equals(TAB3)){ LinearLayout.LayoutParams param3 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT); layout.addView(inflater.inflate(R.layout.item_3, null),param3); } else if(id.equals(TAB4)){ LinearLayout.LayoutParams param4 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT); layout.addView(inflater.inflate(R.layout.item_4, null),param4); } else { TextView tv5 = new TextView(activity); tv5.setText("no resource aviable!"); tv5.setGravity(1); layout.addView(tv5, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT)); } return layout; } } }
最新技术文章: