利用tabhost实现类似QQ、微信界面
来源:互联网 发布:数据库开启事务 编辑:程序博客网 时间:2024/05/18 10:46
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <TabHost android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tabhost"> <LinearLayout android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent"><FrameLayout android:id="@android:id/tabcontent"android:layout_width="fill_parent" android:layout_height="0.0dip"android:layout_weight="1.0" ></FrameLayout><TabWidget android:id="@android:id/tabs" android:visibility="gone"android:layout_width="fill_parent" android:layout_height="wrap_content"android:layout_weight="0.0" /><!-- android:background="@drawable/tabs_bg" --><RadioGroup android:id="@+id/tab_radiogroup"android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center_vertical"android:layout_gravity="bottom" android:orientation="horizontal"><!-- android:drawableTop="@drawable/account01" --><RadioButton android:id="@+id/radio_button_session"android:layout_marginTop="2.0dip" android:checked="true"android:background="@drawable/chat" style="@style/tab_bottom" /><!-- android:drawableTop="@drawable/account02" --><RadioButton android:id="@+id/radio_button_friendlist"android:layout_marginTop="2.0dip" style="@style/tab_bottom" android:background="@drawable/friends" /><!-- android:drawableTop="@drawable/account03"--><RadioButton android:id="@+id/radio_button_find"android:layout_marginTop="2.0dip"style="@style/tab_bottom" android:background="@drawable/discover"/><!--android:drawableTop="@drawable/account04" --><RadioButton android:id="@+id/radio_button_setting"android:layout_marginTop="2.0dip"style="@style/tab_bottom" android:background="@drawable/setting"/></RadioGroup> </LinearLayout></TabHost></LinearLayout><?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <TabHost android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tabhost"> <LinearLayout android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent"><FrameLayout android:id="@android:id/tabcontent"android:layout_width="fill_parent" android:layout_height="0.0dip"android:layout_weight="1.0" ></FrameLayout><TabWidget android:id="@android:id/tabs" android:visibility="gone"android:layout_width="fill_parent" android:layout_height="wrap_content"android:layout_weight="0.0" /><!-- android:background="@drawable/tabs_bg" --><RadioGroup android:id="@+id/tab_radiogroup"android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center_vertical"android:layout_gravity="bottom" android:orientation="horizontal"><!-- android:drawableTop="@drawable/account01" --><RadioButton android:id="@+id/radio_button_session"android:layout_marginTop="2.0dip" android:checked="true"android:background="@drawable/chat" style="@style/tab_bottom" /><!-- android:drawableTop="@drawable/account02" --><RadioButton android:id="@+id/radio_button_friendlist"android:layout_marginTop="2.0dip" style="@style/tab_bottom" android:background="@drawable/friends" /><!-- android:drawableTop="@drawable/account03"--><RadioButton android:id="@+id/radio_button_find"android:layout_marginTop="2.0dip"style="@style/tab_bottom" android:background="@drawable/discover"/><!--android:drawableTop="@drawable/account04" --><RadioButton android:id="@+id/radio_button_setting"android:layout_marginTop="2.0dip"style="@style/tab_bottom" android:background="@drawable/setting"/></RadioGroup> </LinearLayout></TabHost></LinearLayout>
public class ActTabHost extends Activity implements OnCheckedChangeListener {private final String TAG = "ActTabHost";private TabHost tabHost;private Intent sessionIntent; // 会话private Intent friendsListIntent; // 好友private Intent findingIntent; // 发现private Intent settingIntent; // 设置private Thread mThread;private ServiceConnection mServiceConnection = null;private SocketCommunicationService myService = null;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.tabhost);tabHost = (TabHost) findViewById(R.id.tabhost);LocalActivityManager groupActivity = new LocalActivityManager(this,false);groupActivity.dispatchCreate(savedInstanceState);tabHost.setup(groupActivity);// 绑定服务并启动接收消息的服务bindMyReceiveMsgService();// if(mThread == null) {// mThread = new Thread(loadData);// mThread.start();//线程启动// }initIntent();addSpec();((RadioGroup) findViewById(R.id.tab_radiogroup)).setOnCheckedChangeListener(this);};private Handler mHandler = new Handler() {// message对象中包含了线程方法发过来的数据public void handleMessage(Message msg) {}};// 这是一个被后台线程执行的方法,由bnt2的click事件 创建线程并启动Runnable loadData = new Runnable() {public void run() {LoadServerData loaddata = new LoadServerData();if (loaddata.loadFriendsList(Controller.getUserId(), 1))CommonFunctions.generateLogV("100", "从服务器加载好友列表成功!");elseCommonFunctions.generateLogV("100", "从服务器加载好友列表失败!");// 从本地数据库取数据LocalDataProcess localDataProcess = new LocalDataProcess();localDataProcess.downLoadLocalData();CommonFunctions.generateLogV("100", "从本地数据库加载数据完成!");}};/** * 初始化各个tab标签对应的intent */private void initIntent() {sessionIntent = new Intent(this, ActSession.class);friendsListIntent = new Intent(this, ActFriendsList.class);findingIntent = new Intent(this, ActFinding.class);settingIntent = new Intent(this, ActSetting.class);}/** * 为tabHost添加各个标签项 */private void addSpec() {tabHost.addTab(this.buildTagSpec("tab_session", "会话1", R.drawable.chat,sessionIntent));tabHost.addTab(this.buildTagSpec("tab_friendlist", "好友1",R.drawable.friends, friendsListIntent));tabHost.addTab(this.buildTagSpec("tab_finding", "发现1",R.drawable.discover, findingIntent));tabHost.addTab(this.buildTagSpec("tab_setting", "设置1",R.drawable.setting, settingIntent));}/** * 自定义创建标签项的方法 * * @param tagName * 标签标识 * @param tagLable * 标签文字 * @param icon * 标签图标 * @param content * 标签对应的内容 * @return */private TabHost.TabSpec buildTagSpec(String tagName, String tagLable,int icon, Intent content) {return tabHost.newTabSpec(tagName).setIndicator(tagLable, getResources().getDrawable(icon)).setContent(content);}@Overridepublic void onCheckedChanged(RadioGroup group, int checkedId) {// TODO Auto-generated method stubswitch (checkedId) {case R.id.radio_button_session:tabHost.setCurrentTabByTag("tab_session");Controller.setCurrentActivity(ActSession.TAG);break;case R.id.radio_button_friendlist:tabHost.setCurrentTabByTag("tab_friendlist");Controller.setCurrentActivity(ActFriendsList.TAG);break;case R.id.radio_button_find:tabHost.setCurrentTabByTag("tab_finding");Controller.setCurrentActivity(ActFinding.TAG);break;case R.id.radio_button_setting:tabHost.setCurrentTabByTag("tab_setting");Controller.setCurrentActivity(ActSetting.TAG);break;}}public void bindMyReceiveMsgService() {mServiceConnection = new ServiceConnection() {@Overridepublic void onServiceConnected(ComponentName name, IBinder service) {// TODO Auto-generated method stubLocalBinder binder = (LocalBinder) service;myService = binder.getService();myService.startReceiveMsgThread();}@Overridepublic void onServiceDisconnected(ComponentName name) {// TODO Auto-generated method stubCommonFunctions.generateLogV(TAG, "onServiceDisconnected");}};Intent intent = new Intent(ActTabHost.this,SocketCommunicationService.class);if (false == bindService(intent, mServiceConnection,Context.BIND_AUTO_CREATE)) {CommonFunctions.showMessage(ActTabHost.this, "接收消息服务绑定失败!");return;}}}
0 0
- 利用tabhost实现类似QQ、微信界面
- 实现类似QQ、微信聊天界面,标题栏固定,键盘不遮挡底部输入框
- iOS 类似微信,QQ聊天界面的气泡聊天简单实现Demo
- iOS 类似微信,QQ聊天界面的气泡聊天简单实现Demo
- 类似QQ界面的实现
- 利用ImageView + fragment 实现类似QQ消息界面的 点击不同按钮 展示不同界面
- Android: 实现类似QQ、微信的表情输入键盘
- Android: 实现类似QQ、微信的表情输入键盘
- 类似微信的界面
- android 实现类似微信滑动切换界面
- 如何实现类似微信的朋友圈界面?
- 类似qq微信的即时通讯聊天界面是如何定制的
- qq主界面实现(二)-tabHost与fragment配合使用
- android学习笔记----类似微信的TabHost
- 类似qq,微信的消息提醒
- 滑动菜单解决方案之三:使用TabHost控件实现微信界面的底部菜单效果
- 类似QQ展开界面
- 类似QQ聊天界面
- 指针
- HDU4450
- JavaWeb -- Struts2 ResultType细化, 国际化
- android发送彩信
- struts2后台与界面数据交互
- 利用tabhost实现类似QQ、微信界面
- 网线安水晶头制作
- sqlplus 连接远程数据库并创建、授权用户
- xilinx 相关IP核 rom ram
- Amoeba for MySQL 基本介绍
- ecshop二次开发之商品秒杀功能
- strtoul函数的使用
- 寒假学习 第二天 (linux 高级编程)
- Java Collections Framework之TreeMap源码分析(基于JDK1.6)