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. jquery ready()的几种实现方法小结

    几种jQuery的ready ()的写法. 1.最常用也是最标准的  $(document).ready(){  });  2.是上面的简写:  $(function(){  })  很奇怪?为什么能 ...

  2. 管理口令(P):[INS-30001] ADMIN口令为空之Oracle安装

    在安装oracle database11g 发行版的时候出现下面这个问题. 无论怎么输入密码都提示有问题,都输入得鬼火了!去百度了一下,果然有命名规则的 规则如下:小写字母+数字+大写字母

  3. MySQL 5.7.9多源复制报错修复

    版本:5.7.9 用5.7.9的版本搭建MySQL多源复制测试环境 开发说复制出现问题,上去看了一下: mysql> show slave status\G******************* ...

  4. 如何正确理解深度学习(Deep Learning)的概念

    现在深度学习在机器学习领域是一个很热的概念,不过经过各种媒体的转载播报,这个概念也逐渐变得有些神话的感觉:例如,人们可能认为,深度学习是一种能够模拟出人脑的神经结构的机器学习方式,从而能够让计算机具有 ...

  5. Python中的除法

    在C/C++语言对于整形数执行除法会进行地板除(舍去小数部分).例如 int a=15/10; a的结果为1. 同样的在Java中也是如此,所以两个int型的数据相除需要返回一个浮点型数据的时候就需要 ...

  6. JDBC连接数据库代码

    //连接是需要导包 http://pan.baidu.com/s/1o6nyuOa /*配合数据库建立表 create database day14 character set utf8 collat ...

  7. SQL SERVER 強制指定使用索引 -转载 只为学习

    今天很高兴 ,有学会了一种数据库优化的方式,哈哈 今天遇到一個查詢逾時的問題:兩段SQL,只差在WHERE,一個是WHERE COLUMN1='AAA',一個是WHERE COLUMN1='BBB', ...

  8. OpenCV+QT开发环境(一):Windows环境

    最近在学习openCV的开发.在搭建开发环境的时候,着实废了不少功夫,找了大量的文章资料.其实主要的开发还是在linux系统上的openCV,但是为了方便,我还是在windows上也搭建了开发环境,这 ...

  9. IntelliJ IDEA 调试小记

    一.IntelliJ IDEA 调试没有F6 Eclipse调试有F6,意为下一步,递增F8.可IntelliJ IDEA 调试没有这个. 二.图解 Step Over (F8): 下一步 (相当于E ...

  10. 【技术贴】解决MySql连接不上 ip远程连接Host is not allowed to conn

    落雨 如果你想连接远程IP的mysql的时候发生这个错误: ERROR 1130: Host '192.168.1.3' is not allowed to connect to this MySQL ...