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. AS3 - 数组Array的几个常用方法(附样例)

    AS3 - 数组Array的几个常用方法(附样例) 2015-03-30 10:39发布:hangge浏览:241   Flex/Flash开发中,经常会使用到数组,下面总结了一些数组的常用方法. 1 ...

  2. C# 反射学习总结

    C#中的反射可以使得程序集和类型(类.结构.委托.接口和枚举)以及类型中的成员(方法.字段.属性.事件.参数.构造函数等)都成为变量在编程中动态调用.

  3. Linux挂载60T存储

    操作系统: CentOS 6.3 存储:总大小为72T,并划分成3个块,每块20T 安装多实例MySQL数据库,不想挂载3个块,弄成一个大的比较方便管理,个人比较懒. 配置多路径:http://blo ...

  4. VS2010性能监视工具

    <编程珠玑(续)>第一章中就介绍了性能监视工具,对于较简单的程序来说,性能监视工具其实可以用变量累加来计算的,但是对于较复杂的程序来说就需要比较好的性能监视工具了.而VS2010提供了一个 ...

  5. JAVA类与对象(二)----类定义基础

    类是组成java程序的基本要素,是java中的一种重要的复合数据类型.它封装了一类对象的状态和方法,是这一类对象的原型.一个类的实现包括两个部分:类声明和类体,基本格式: class <clas ...

  6. 小王子浅读Effective javascript(一)了解javascript版本

    哈哈,各位园友新年快乐!愚安好久没在园子里写东西了,这次决定针对javascript做一个系列,叫做<小王子浅读Effective javascript>,主要是按照David Herma ...

  7. c++ std::string 用法

    std::string用法总结 在平常工作中经常用到了string类,本人记忆了不好用到了的时候经常要去查询.在网上摘抄一下总结一下,为以后的查询方便: string类的构造函数: string(co ...

  8. Mongo:将查询结果转换为自定义类

    1.自定义类 public class MyClass { public string Name { get; set; } public int Corners { get; set; } } 2. ...

  9. CSS透明属性详解代码

    透明往往能产生不错的网页视觉效果,先奉上兼容主流浏览器的CSS透明代码: 代码如下: .transparent_class { filter:alpha(opacity=50); -moz-opaci ...

  10. HTML教程XHTML教程:HTML标记嵌套使用技巧

    网页制作Webjx文章简介:WEB标准-HTML元素嵌套. 先来看以下这样一段代码: <ul>    <li><h4><a href="" ...