Android:PopupWindow简单弹窗改进版
继续上一节的内容,改进一下,目标是点击菜单后把菜单收缩回去并且切换内容,我使用的是PopupWindow+RadioGroup

public class MainActivity extends TabActivity {
private PopupWindow pop;
private TabHost tabhost;
private RadioGroup radiogroup;
private RadioButton tab1,tab2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test);
//将layout的xml布局文件实例化为View类对象
LayoutInflater inflater =LayoutInflater.from(this);
View view =inflater.inflate(R.layout.mypop, null);
//创建PopupWindow,参数为显示对象,宽,高
pop =new PopupWindow(view, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
//PopupWindow的设置
pop.setBackgroundDrawable(new BitmapDrawable());
//点击外边消失
pop.setOutsideTouchable(true);
//设置此参数获得焦点,否则无法点击
pop.setFocusable(true);
//设置文本监听事件
TextView text =(TextView) findViewById(R.id.topmenu);
text.setOnClickListener(new OnClickListener(){
@Override
//判断是否已经显示,点击时如显示则隐藏,隐藏则显示
public void onClick(View v) {
if(pop.isShowing()){
pop.dismiss();
}else{
pop.showAsDropDown(v);
}
}
});
//tabhost
tabhost=getTabHost();
tabhost.addTab(tabhost.newTabSpec("a").setContent(R.id.tab1).setIndicator("a"));
tabhost.addTab(tabhost.newTabSpec("b").setContent(R.id.tab2).setIndicator("b"));
//选项
radiogroup = (RadioGroup) view.findViewById(R.id.radiogroup);
//设置radiobutton监听事件
radioCheckListener l =new radioCheckListener();
radiogroup.setOnCheckedChangeListener(l);
}
//点击菜单,切换卡并让菜单消失
public class radioCheckListener implements OnCheckedChangeListener{
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
switch(checkedId){
case R.id.tabps:
tabhost.setCurrentTab(0);
pop.dismiss();
break;
case R.id.tabhtml:
tabhost.setCurrentTab(1);
pop.dismiss();
break;
}
}
}
}
菜单布局:
<?xml version="1.0" encoding="utf-8"?>
<RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#393C39"
android:padding="10dp"
android:id="@+id/radiogroup"
> <RadioButton
android:id="@+id/tabps"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Photoshop"
android:textColor="#ffffff"
android:checked="true"
/> <RadioButton
android:id="@+id/tabhtml"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="#ffffff"
android:text="HTML"
/> </RadioGroup>
主布局:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@android:id/tabhost"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/titlebg"
android:gravity="center"
android:orientation="vertical" > <TextView
android:id="@+id/topmenu"
android:layout_width="wrap_content"
android:layout_height="46dp"
android:clickable="true"
android:drawableRight="@drawable/ic_menu_trangle_down"
android:gravity="center_vertical"
android:text="全部课程"
android:textColor="#ffffff" />
</LinearLayout> <TabWidget
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@android:id/tabs"
android:visibility="gone"
>
</TabWidget> <FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@android:id/tabcontent"
>
<LinearLayout
android:id="@+id/tab1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#ff0000"
></LinearLayout>
<LinearLayout
android:id="@+id/tab2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#000000"
></LinearLayout>
</FrameLayout>
</LinearLayout> </TabHost>
相关文章:
Android:PopupWindow简单弹窗改进版的更多相关文章
- Android:PopupWindow简单弹窗
两布局,一个当前布局页面和一个点击展示布局页面,主程序代码: public class MainActivity extends Activity { private PopupWindow pop; ...
- Android PopupWindow的使用和分析
Android PopupWindow的使用和分析 PopupWindow使用 PopupWindow这个类用来实现一个弹出框,可以使用任意布局的View作为其内容,这个弹出框是悬浮在当前activi ...
- Android发展简单介绍
Android一词的本义指“机器人”,同一时候也是Google于2007年11月5日宣布的基于Linux平台的开源手机操作系统的名称,该平台由操作系统.中间件.用户界面和应用软件组成,号称是首个为移动 ...
- Android PopupWindow的使用技巧(转)
Android PopupWindow的使用技巧 PopupWindow是Android上自定义弹出窗口,使用起来很方便. PopupWindow的构造函数为 public PopupWindow(V ...
- Android PopupWindow Dialog 关于 is your activity running 崩溃详解
Android PopupWindow Dialog 关于 is your activity running 崩溃详解 [TOC] 起因 对于 PopupWindow Dialog 需要 Activi ...
- Android 实现简单音乐播放器(二)
在Android 实现简单音乐播放器(一)中,我介绍了MusicPlayer的页面设计. 现在,我简单总结一些功能实现过程中的要点和有趣的细节,结合MainActivity.java代码进行说明(写出 ...
- Android 实现简单音乐播放器(一)
今天掐指一算,学习Android长达近两个月了,今天开始,对过去一段时间的学习收获以及遇到的疑难杂症做一些总结. 简单音乐播放器是我自己完成的第一个功能较为完整的APP,可以说是我的Android学习 ...
- Android课程---Android Studio简单设置
Android Studio 简单设置 界面设置 默认的 Android Studio 为灰色界面,可以选择使用炫酷的黑色界面.Settings-->Appearance-->Theme, ...
- Android实现简单音乐播放器(MediaPlayer)
Android实现简单音乐播放器(MediaPlayer) 开发工具:Andorid Studio 1.3 运行环境:Android 4.4 KitKat 工程内容 实现一个简单的音乐播放器,要求功能 ...
随机推荐
- 每日一“酷”之string
介绍:string模块可以追溯到最早的Python版本中.现在很多的被移植为str和unicode对象的方法,在python3.0中会被完全去除.string模块中,有很多有用的常量和累,用来处理st ...
- 2014年互联网IT待遇(包括国内民企、外企、金融机构)
一.民企 1. 百度 13k*14.6,special 14~17k*14.6 开发类 13K*14.6 (2014) 测试类.前端类 12K*14.6 (2014) 2. 腾讯 11.5k*16,s ...
- poj 3237 Tree 树链剖分+线段树
Description You are given a tree with N nodes. The tree’s nodes are numbered 1 through N and its edg ...
- cadence 机械孔的制作
在平时画PCB的时候,会用到安装孔,好多人就是找个过孔,在原理图中连接GND,这样使用也可以,下面介绍一种正经机械孔的制作方法(自己摸索的),制作一个孔径为3mm的安装孔. 1 打开pad desig ...
- python之函数嵌套
python很多特性与JavaScript是相似甚至相同的: 1. 无类型 2. 函数亦对象 .... 自然: python也允许函数嵌套, 这与JavaScript中函数闭包的作用一样....
- 史上最全的Excel数据编辑处理技巧(转)
史上最全的数据编辑处理技巧,让你在日常数据分析处理的疯魔状态中解放出来. 一.隐藏行列 “不得了了,Excel出现灵异事件,部分区域消失不见了!”办公室里的一个MM跑过来大声喊叫着,着实吓了俺一跳.待 ...
- VS2010 配置opencv环境
大家在使用opencv的时候肯定会面对这样一个问题:根据官网以及大多数教程提供的方法中,似乎每一次新建一个opencv的新项目以后都需要重新再配置"VC++目录"中的"包 ...
- Pentaho Data Integration笔记 (一):安装
介绍 Pentaho Data Integration (PDI) is an extract, transform, and load (ETL) solution that uses an inn ...
- C#截取文件的文件夹地址
创建文件 if (!File.Exists(file_name)) { File.Create(file_name).Close(); } using System.IO; 如果没有.Close(), ...
- js获取对象、数组的实际长度,元素实际个数
/*获取对象.数组的长度.元素个数 *@param obj 要计算长度的元素,可以为object.array.string */ function count(obj){ var objType = ...