android PopupWindow
16lz
2021-12-04
<?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; @Overrideprotected 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 ); }@Overridepublic 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;}} }
更多相关文章
- 【android】利用Yahoo API完成天气预报
- Android(安卓)TextView内容过长加省略号,点击显示全部内容
- Android(安卓)TextView内容过长加省略号,点击显示全部内容
- Android属性动画-Property Animation(三) 使用ValueAnimator完成
- Android:解决ListView按下后上下滑动背景全部变黑的问题
- Android(安卓)Launcher3去除应用列表,二级菜单,应用全部在桌面显示
- 自定义tabhost实现
- TabHost与RadioGroup结合完成的菜单
- 安装Intel HAXM为Android(安卓)模拟器加速,30秒内启动完成