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实现下拉导航选择菜单效果

Android:PopupWindow简单弹窗改进版的更多相关文章

  1. Android:PopupWindow简单弹窗

    两布局,一个当前布局页面和一个点击展示布局页面,主程序代码: public class MainActivity extends Activity { private PopupWindow pop; ...

  2. Android PopupWindow的使用和分析

    Android PopupWindow的使用和分析 PopupWindow使用 PopupWindow这个类用来实现一个弹出框,可以使用任意布局的View作为其内容,这个弹出框是悬浮在当前activi ...

  3. Android发展简单介绍

    Android一词的本义指“机器人”,同一时候也是Google于2007年11月5日宣布的基于Linux平台的开源手机操作系统的名称,该平台由操作系统.中间件.用户界面和应用软件组成,号称是首个为移动 ...

  4. Android PopupWindow的使用技巧(转)

    Android PopupWindow的使用技巧 PopupWindow是Android上自定义弹出窗口,使用起来很方便. PopupWindow的构造函数为 public PopupWindow(V ...

  5. Android PopupWindow Dialog 关于 is your activity running 崩溃详解

    Android PopupWindow Dialog 关于 is your activity running 崩溃详解 [TOC] 起因 对于 PopupWindow Dialog 需要 Activi ...

  6. Android 实现简单音乐播放器(二)

    在Android 实现简单音乐播放器(一)中,我介绍了MusicPlayer的页面设计. 现在,我简单总结一些功能实现过程中的要点和有趣的细节,结合MainActivity.java代码进行说明(写出 ...

  7. Android 实现简单音乐播放器(一)

    今天掐指一算,学习Android长达近两个月了,今天开始,对过去一段时间的学习收获以及遇到的疑难杂症做一些总结. 简单音乐播放器是我自己完成的第一个功能较为完整的APP,可以说是我的Android学习 ...

  8. Android课程---Android Studio简单设置

    Android Studio 简单设置 界面设置 默认的 Android Studio 为灰色界面,可以选择使用炫酷的黑色界面.Settings-->Appearance-->Theme, ...

  9. Android实现简单音乐播放器(MediaPlayer)

    Android实现简单音乐播放器(MediaPlayer) 开发工具:Andorid Studio 1.3 运行环境:Android 4.4 KitKat 工程内容 实现一个简单的音乐播放器,要求功能 ...

随机推荐

  1. sublimetext2 中运行Python提示EOFError: EOF when reading a line

    解决方法:一.安装sublimeREPL    打开sublimeText2按CTRL+SHIFT+P,英文版输入:install后选择Package Control: Install Package ...

  2. Linux使用标准IO的调用函数,分3种形式实现

    /*根据cp命令的格式要求,设计一个类cp的功能程序,要求使用标准IO的调用函数,分3种形式实现,字符,行,块.并注意函数功能的分层*/ #include<stdio.h> #includ ...

  3. CentOS thrift python demo

    编辑接口文件 hellowworld.thrift service HelloWorld { string ping(), string say(1:string msg) } 编辑 server.p ...

  4. MYSQL 配置slave故障

    之前为主从配置,后来分割成2个单实例.现在环境需要,重新配置为主从,之前参数都已配置好,直接启动,如下: mysql> change master to master_host='192.168 ...

  5. Context详解

    前言 Context在android中的作用不言而喻,当我们访问当前应用的资源,启动一个新的activity的时候都需要提供Context,而这个Context到底是什么呢,这个问题好像很好回答又好像 ...

  6. C# list 筛选FindAll,根据参数过滤

    /// <summary> /// 汽车车型 获取 /// Redis Key=zgqp315_Redis_ModelNumberC_List /// </summary> / ...

  7. Ha ha lou!

    忙了一个晚上,终于稍微把这个模板修缮好了一点=-=//,然而我并不知道怎么像别的大牛一样,博客跟自己做的页面一样.总之今天就先到这里啦! 我的QQ是270115270,不知道会不会有人来呢=-=. ( ...

  8. Lua基础之字符串(string)

    1,计算字符串长度 2,返回字符串s的n个拷贝 3,返回字符串全部字母大写 4,返回字符串全部字母小写 5,返回一个类似printf的格式化字符串 6,根据下标截取字符串 7,在字符串中查找 8,在字 ...

  9. 51nod 1257 背包问题 V3

    1257 背包问题 V3 基准时间限制:3 秒 空间限制:131072 KB 分值: 80 难度:5级算法题 N个物品的体积为W1,W2......Wn(Wi为整数),与之相对应的价值为P1,P2.. ...

  10. Javascript 面向对象编程

    Javascript是一个类C的语言,他的面向对象的东西相对于C++/Java比较奇怪,但是其的确相当的强大,在 Todd 同学的“对象的消息模型”一文中我们已经可以看到一些端倪了.这两天有个前同事总 ...