android PopupWindow




 



 

 

<?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="completed"
        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="Not done"
        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;
		}
	}
	 
}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Donate to developers

Driven by interest, I write 免费something with joy and sweat. I hope you like my work and can support it at the same time. Of course, if you have money to support a money field (the love sign in the upper right corner, support Alipay and PayPal donations), if you have no money to support a personal field, thank you.



 
 
 Thank you for your sponsorship, I will do better!

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326942728&siteId=291194637