android的tabhost+RadioGroup+PopupWindow
根据网上的代码稍作修改了下,放着记录学习。
效果图如下:
主代码如下:
package com.andyidea.tabdemo; import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RadioButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.TabHost;
import android.widget.Toast; public class MainTabActivity extends TabActivity implements
OnCheckedChangeListener, OnClickListener
{ private TabHost mTabHost; private Intent mAIntent; private Intent mBIntent; private Intent mCIntent; private Intent mDIntent; private Intent mEIntent; private PopupWindow mPopupWindow; private RadioButton mR1; private RadioButton mR2; private RadioButton mR3; private RadioButton mR4; private LinearLayout mLinearLayout1; private LinearLayout mLinearLayout2; private LinearLayout mLinearLayout3; private LinearLayout mLinearLayout4; private LinearLayout mLinearLayout5; /**
* 基准屏幕密度
*/
public double STANDARD_DENSITY = 160; /** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.maintabs); this.mAIntent = new Intent(this, AActivity.class);
this.mBIntent = new Intent(this, BActivity.class);
this.mCIntent = new Intent(this, CActivity.class);
this.mDIntent = new Intent(this, DActivity.class);
this.mEIntent = new Intent(this, EActivity.class); mR1 = ((RadioButton) findViewById(R.id.radio_button0));
mR1.setOnCheckedChangeListener(this);
mR2 = ((RadioButton) findViewById(R.id.radio_button1));
mR2.setOnCheckedChangeListener(this);
mR3 = ((RadioButton) findViewById(R.id.radio_button2));
mR3.setOnCheckedChangeListener(this);
mR4 = ((RadioButton) findViewById(R.id.radio_button3));
mR4.setOnCheckedChangeListener(this); setupIntent();
initPopupMenu();
} private void initPopupMenu()
{
View mPopupMenu =
LayoutInflater.from(this).inflate(R.layout.popupmenu, null); mPopupWindow =
new PopupWindow(mPopupMenu, (int) (getDensityRatio() * 90),
(int) (getDensityRatio() * 180));
mLinearLayout1 = (LinearLayout) mPopupMenu.findViewById(R.id.zhanghao);
mLinearLayout2 = (LinearLayout) mPopupMenu.findViewById(R.id.firav);
mLinearLayout3 = (LinearLayout) mPopupMenu.findViewById(R.id.yijian);
mLinearLayout4 = (LinearLayout) mPopupMenu.findViewById(R.id.abort);
mLinearLayout5 = (LinearLayout) mPopupMenu.findViewById(R.id.update);
mLinearLayout1.setOnClickListener(this);
mLinearLayout2.setOnClickListener(this);
mLinearLayout3.setOnClickListener(this);
mLinearLayout4.setOnClickListener(this);
mLinearLayout5.setOnClickListener(this); } private void dissmissPopupWindows()
{
if (mPopupWindow != null && mPopupWindow.isShowing())
{
mPopupWindow.dismiss();
}
} private double getDensityRatio()
{
DisplayMetrics displayMetrics = new DisplayMetrics();
Display display = getWindowManager().getDefaultDisplay();
display.getMetrics(displayMetrics); double w = displayMetrics.widthPixels;
double h = displayMetrics.heightPixels;
int CURRENT_DENSITY = displayMetrics.densityDpi;
double DENSITY_RATIO = CURRENT_DENSITY / STANDARD_DENSITY;
return DENSITY_RATIO;
} @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
{
if (isChecked)
{
System.out.println("isChecked");
dissmissPopupWindows();
switch (buttonView.getId())
{
case R.id.radio_button0:
this.mTabHost.setCurrentTabByTag("A_TAB");
break;
case R.id.radio_button1:
this.mTabHost.setCurrentTabByTag("B_TAB");
break;
case R.id.radio_button2:
this.mTabHost.setCurrentTabByTag("C_TAB");
break;
case R.id.radio_button3:
mPopupWindow.showAsDropDown(mR4, 0, 0);
break;
}
} } private void setupIntent()
{
this.mTabHost = getTabHost();
TabHost localTabHost = this.mTabHost; localTabHost.addTab(buildTabSpec("A_TAB", R.string.main_news,
R.drawable.icon_1_n, this.mAIntent)); localTabHost.addTab(buildTabSpec("B_TAB", R.string.main_down,
R.drawable.icon_2_n, this.mBIntent)); localTabHost.addTab(buildTabSpec("C_TAB", R.string.main_message,
R.drawable.icon_3_n, this.mCIntent)); localTabHost.addTab(buildTabSpec("D_TAB", R.string.more,
R.drawable.icon_4_n, this.mDIntent));
} private TabHost.TabSpec buildTabSpec(String tag, int resLabel, int resIcon,
final Intent content)
{
return this.mTabHost
.newTabSpec(tag)
.setIndicator(getString(resLabel),
getResources().getDrawable(resIcon))
.setContent(content);
} @Override
public void onClick(View v)
{
dissmissPopupWindows();
switch (v.getId())
{
case R.id.zhanghao:
Toast.makeText(MainTabActivity.this, "账号管理", Toast.LENGTH_SHORT)
.show();
break;
case R.id.firav:
Toast.makeText(MainTabActivity.this, "收藏夹", Toast.LENGTH_SHORT)
.show();
break;
case R.id.yijian:
Toast.makeText(MainTabActivity.this, "意见反馈", Toast.LENGTH_SHORT)
.show();
break;
case R.id.abort:
Toast.makeText(MainTabActivity.this, "关于我们", Toast.LENGTH_SHORT)
.show();
break;
case R.id.update:
Toast.makeText(MainTabActivity.this, "版本更新", Toast.LENGTH_SHORT)
.show();
break;
}
}
}
点击我下载源码:
android的tabhost+RadioGroup+PopupWindow的更多相关文章
- android中TabHost和RadioGroup
android底部菜单应用 博客分类: android--UI示例 TabHostMenuRadioGroupButton 在android中实现菜单功能有多种方法. Options Menu:用户 ...
- android之TabHost(下)
首先建立res/layout/tab.xml文件 编写代码如下: <?xml version="1.0" encoding="utf-8"?> &l ...
- android之TabHost(上)
首先建立文件res/layout/tab.xml 代码如下: <?xml version="1.0" encoding="utf-8"?> < ...
- 底部菜单栏(二) TabHost & RadioGroup 实现
需求:使用TabHost & RadioGroup实现底部菜单栏: 效果图: 实现分析: 1.目录结构: 代码实现: 1. activity_main.xml <?xml version ...
- android学习--TabHost选项卡组件
TabHost是一种非常有用的组件,TabHost能够非常方便地在窗体上放置多个标签页,每一个标签页获得了一个与外部容器同样大小的组件摆放区域.在手机系统的应用类似"未接电话".& ...
- Android ViewPager+TabHost实现首页导航
今天发的是TabHost结合ViewPager实现首页底部导航的效果,虽然说网上有很多这样的Demo,不过呢,我还是要把自己练习写的发出来,没错!就是这么任性: 先上效果图,如下: 代码里面有注释,就 ...
- android 之 TabHost
TabHost的实现有两种方式,第一种继承TabActivity,从TabActivity中用getTabHost()方法获取TabHost.各个Tab中的内容在布局文件中定义就行了. mainAct ...
- Android底部TabHost API
今天在项目中遇到了底部TabHost,顺便就写了一个底部TabHost的api继承即可使用非常简单,以下为源代码: 首先是自定义的TabHostActivity,如果要使用该TabHost继承该类即可 ...
- 12.Android之Tabhost组件学习
TabHost是整个Tab的容器,TabHost的实现有两种方式: 第一种继承TabActivity,从TabActivity中用getTabHost()方法获取TabHost.各个Tab中的内容在布 ...
随机推荐
- 要想重启后也生效LINUX防火墙配置
新配置的一台服务器,安装的是CentOS6.3系统,在安装完LNMP之后,发现nginx进程存在,且php解析正常,但是用分配的独立IP去访问的时候发现无法访问. 查了下网上的资料,发现可能是Linu ...
- HDU 5491 The Next
Problem Description Let L denote the number of 1s in integer D’s binary representation. Given two in ...
- webapp框架—学习AngularUI2(demo改造)
目的:把AngularUI的模板应用到“桂电在线”上 步骤如下: 按功能表修改demo界面 学习angularUI如何加载全部页面,为了设置自定义加载模板,在demo/demo.js中找到这一段 // ...
- Amazon's NoSQL Journey and AWS Operations
AWS: Amazon Web Services 提供了一整套基础设施和应用程序服务,使您几乎能够在云中运行一切应用程序:从企业应用程序和大数据项目,到社交游戏和移动应用程序. 计算类: EC2:弹性 ...
- NSURLSession -- 实际开发中运用
NSURLSession实际请求 iOS9使用http请求方法: 在工程info.plist文件内添加NSAppTransportSecurity键,类型为dictionary 在NSAppTrans ...
- Python如何进行cross validation training
以4-fold validation training为例 (1) 给定数据集data和标签集label 样本个数为 sampNum = len(data) (2) 将给定的所有examples分为1 ...
- [BZOJ - 2631] tree 【LCT】
题目链接:BZOJ - 2631 题目分析 LCT,像线段树区间乘,区间加那样打标记. 这道题我调了一下午. 提交之后TLE了,我一直以为是写错了导致了死循环. 于是一直在排查错误.直到.. 直到我看 ...
- [MVC] WebSecurity在VS2013中不识别
使用VS2013创建了MVC4项目以后,在filters中添加了类InitializeSimpleMembershipAttribute ,不能识别UserContext和WebSecurity,发现 ...
- Android应用程序的生命周期
转自Android应用程序的生命周期 在对一个简单的Hello World工程进行项目结构剖析后,我们接着来学习下一个Android应用程序的生命周期是怎么样的,以便为后面的开发有个垫下良好的基石~ ...
- python 大文件以行为单位读取方式比对
http://www.cnblogs.com/aicro/p/3371986.html 先前需要做一个使用python读取大文件(大于1G),并逐条存入内存进行处理的工作.做了很多的尝试,最终看到了如 ...