当前位置:  编程技术>移动开发
本页文章导读:
    ▪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

    
[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实例
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;
    }
	
}


}

    
最新技术文章:
▪Android开发之登录验证实例教程
▪Android开发之注册登录方法示例
▪Android获取手机SIM卡运营商信息的方法
▪Android实现将已发送的短信写入短信数据库的...
▪Android发送短信功能代码
▪Android根据电话号码获得联系人头像实例代码
▪Android中GPS定位的用法实例
▪Android实现退出时关闭所有Activity的方法
▪Android实现文件的分割和组装
▪Android录音应用实例教程
▪Android双击返回键退出程序的实现方法
▪Android实现侦听电池状态显示、电量及充电动...
▪Android获取当前已连接的wifi信号强度的方法
▪Android实现动态显示或隐藏密码输入框的内容
▪根据USER-AGENT判断手机类型并跳转到相应的app...
▪Android Touch事件分发过程详解
▪Android中实现为TextView添加多个可点击的文本
▪Android程序设计之AIDL实例详解
▪Android显式启动与隐式启动Activity的区别介绍
▪Android按钮单击事件的四种常用写法总结
▪Android消息处理机制Looper和Handler详解
▪Android实现Back功能代码片段总结
▪Android实用的代码片段 常用代码总结
▪Android实现弹出键盘的方法
▪Android中通过view方式获取当前Activity的屏幕截...
▪Android提高之自定义Menu(TabMenu)实现方法
▪Android提高之多方向抽屉实现方法
▪Android提高之MediaPlayer播放网络音频的实现方法...
▪Android提高之MediaPlayer播放网络视频的实现方法...
▪Android提高之手游转电视游戏的模拟操控
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3