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 工程内容 实现一个简单的音乐播放器,要求功能 ...
随机推荐
- RGB颜色二值化
原理:RGB颜色根据计算'灰度'的公式,可以转化为黑白2种颜色,实现二值化. 业务场景的应用:可以根据背景颜色,取一个黑色或白色的颜色,作为背景色上的文案字体颜色 具体代码: function get ...
- mysql命令语句来去除掉字段中空格字符的方法
mysql有什么办法批量去掉某个字段字符中的空格?不仅是字符串前后的空格,还包含字符串中间的空格,答案是 replace,使用mysql自带的 replace 函数,另外还有个 trim 函数. ...
- struts2结构图
- Delphi ISO 收藏!
CodeGear RAD Studio 2007 最终版(With Update4) v11.0.2902.10471http://altd.codegear.com/download/radstud ...
- apache ab的安装步骤
1:到apache官方网站http://httpd.apache.org/download.cgi#apache24下载最新版本的apache,然后解压,执行如下命令: ./configure –pr ...
- C# 缓存学习第一天
缓存应用目的:缓存主要是为了提高数据的读取速度.因为服务器和应用客户端之间存在着流量的瓶颈,所以读取大容量数据时,使用缓存来直接为客户端服务,可以减少客户端与服务器端的数据交互,从而大大提高程序的性能 ...
- C# 实例化接口对象
在head first 设计模式中 用到了很多很多接口对象 首先澄清一个问题,就是接口不仅可以声明对象,而且可以把对象实例化,还可以当做参数被传入. 一.接口回调 这就是继承中的向上转型.父类 FL= ...
- TAG的用法和用途[转]
用一个例子来说明:一个combobox控件...一个textBox控件...一个datagridview控件!datagridview控件是连接数据库的...combobox和textBox是联合查询 ...
- 关于表 datatable的条件查询
关于表 datatable的条件查询 从数据库中获得一个datatable dt .里面有很多的死的数据.然后,我就是要在这个表中来按条件查询,例如 dt中有个列叫"palte", ...
- 移植linux4.7.2与ubifs到jz2440
前言 整个暑假跟着韦东山的视频和书籍移植了linux2.3.6到jz2440,现在自己尝试移植linux4.7.2到板子上,并使用ubifs文件系统代替旧的jffs2文件系统. 下载交叉编译工具链 工 ...