android PopupWindow

简介:                 package com.example.




 



 

 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_horizontal"
    android:orientation="vertical"
    android:paddingLeft="15dp"
    android:paddingRight="15dp"
    android:background="@color/grey" >

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@android:drawable/divider_horizontal_bright" />

    <TextView
        android:id="@+id/tv_all_state"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#ECF0F2"
        android:gravity="center"
        android:padding="10dp"
        android:text="全部"
        android:textColor="@color/black" />

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@android:drawable/divider_horizontal_bright" />

    <TextView
        android:id="@+id/tv_done"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#ECF0F2"
        android:gravity="center"
        android:padding="10dp"
        android:text="已完成"
        android:textColor="@color/black" />

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@android:drawable/divider_horizontal_bright" />

    <TextView
        android:id="@+id/tv_undo"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#ECF0F2"
        android:gravity="center"
        android:padding="10dp"
        android:text="未完成"
        android:textColor="@color/black" />

</LinearLayout>

 

 

 

 

 

package com.example.demopopupwindow.activity;
 

import com.example.demopopupwindow.R; 

import android.app.Activity; 
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle; 
import android.view.View;
import android.view.View.OnClickListener; 
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.LinearLayout.LayoutParams;

public class PopupWindowActivity extends Activity implements OnClickListener{

	 private TextView                   mTopChooseBar;
	 private PopupWindow                mPopupWindow;
	 private TextView                   mTvDone; 
	 private TextView                   mTvUnDo; 
	 private TextView                   mTvAllState;
	 
	 
	  @Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

	    mTopChooseBar = (TextView) this.findViewById( R.id.tv_topbar);
	    mTopChooseBar.setOnClickListener(this);
        setOnChooseListener();
		
	}
	  
	 
	 
	 public void setOnChooseListener() {
		View view = View.inflate( this, R.layout.topbar, null );
        mTvDone = ( TextView ) view.findViewById( R.id.tv_done );
        mTvUnDo = ( TextView ) view.findViewById( R.id.tv_undo );
        mTvAllState = ( TextView ) view.findViewById( R.id.tv_all_state );

        mPopupWindow = new PopupWindow(view ,LayoutParams.MATCH_PARENT,
                LayoutParams.WRAP_CONTENT, false );
        mPopupWindow.setBackgroundDrawable( new BitmapDrawable() );
        mPopupWindow.setOutsideTouchable( true );
        mPopupWindow.setFocusable( true );

        mTopChooseBar.setOnClickListener( this );
        mTvDone.setOnClickListener( this );
        mTvUnDo.setOnClickListener( this );
        mTvAllState.setOnClickListener( this );
	    }

	@Override
	public void onClick(View v) { 
		switch (v.getId()) {
		case R.id.tv_topbar:
			if ( mPopupWindow.isShowing() ) {
                mPopupWindow.dismiss();
            }
            else {
                mPopupWindow.showAsDropDown( v );
            }
			break;
		case R.id.tv_done:
			mTopChooseBar.setText( mTvDone.getText() );
            mPopupWindow.dismiss();
			break;
		case R.id.tv_undo:
			 mTopChooseBar.setText( mTvUnDo.getText() );
             mPopupWindow.dismiss();
			break;
		case R.id.tv_all_state:
			 mTopChooseBar.setText( mTvAllState.getText() );
             mPopupWindow.dismiss();
			break;
	
		default:
			break;
		}
	}
	 
}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

捐助开发者

在兴趣的驱动下,写一个免费的东西,有欣喜,也还有汗水,希望你喜欢我的作品,同时也能支持一下。 当然,有钱捧个钱场(右上角的爱心标志,支持支付宝和PayPal捐助),没钱捧个人场,谢谢各位。



 
 
 谢谢您的赞助,我会做的更好!

 

 

目录
相关文章
|
Android开发
Android 封装一个通用的PopupWindow
`PopupWindow`这个类用来实现一个弹出框,可以使用任意布局的`View`作为其内容,这个弹出框是悬浮在当前`Activity`之上的,一般`PopupWindow`的使用
231 0
|
XML JSON Java
android 继承popupWindow实现时间、地址选择器
日期选择、地址选择,都是开发中少不了的功能,下面通过自定义的形式,同一套代码实现时间选择与地址选择,通过构造方法的不同来实现。
444 0
android 继承popupWindow实现时间、地址选择器
|
Android开发
Android 7.0及以上PopupWindow 适配问题
Android 7.0及以上PopupWindow 适配问题
106 0
|
XML Android开发 iOS开发
Android 仿IOS的PopupWindow和通用BasePopupWindow搭建
截图 pw.png 实现 1、BasePopupWindow.java 1.1、实现动态加载不同layout 1.2、动态配置是否弹出后背景半透明,关闭时候恢复(监听ondismiss,靠window类来变色) 1.
2344 0
|
Android开发
Android项目实战(十七):QQ空间实现(二)—— 分享功能 / 弹出PopupWindow
原文:Android项目实战(十七):QQ空间实现(二)—— 分享功能 / 弹出PopupWindow 这是一张QQ空间说说详情的截图。 分析: 1、点击右上角三个点的图标,在界面底部弹出一个区域,这个区域有一些按钮提供给我们操作 2、当该区域出现的时候,详情界面便灰了,也说成透明度变...
888 0
|
Android开发
Android弹窗二则: PopupWindow和AlertDialog
前言 弹窗是图形界面必备的一个模块, 回忆一下windows那些恶心爆了的错误弹窗吧, 把弹窗制作的更高效友好一点是非常必要的. 这里说两个常用的弹窗类, PopupWindow和AlertDialog.
1121 0