
<?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捐助),沒錢捧個人場,謝謝各位。
謝謝您的贊助,我會做的更好!