這期內(nèi)容當(dāng)中小編將會給大家?guī)碛嘘P(guān)Popupwindow怎么在Android應(yīng)用中使用,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。

站在用戶的角度思考問題,與客戶深入溝通,找到揚(yáng)州網(wǎng)站設(shè)計與揚(yáng)州網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗,讓設(shè)計與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個性化、用戶體驗好的作品,建站類型包括:網(wǎng)站設(shè)計、成都做網(wǎng)站、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、域名申請、虛擬空間、企業(yè)郵箱。業(yè)務(wù)覆蓋揚(yáng)州地區(qū)。
第一步:
private PopupWindow mPopupWindow;
第二步:寫一個popupwindow的布局文件XML
<?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:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#669E9E9E">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#E4E4E4"
>
<TextView
android:id="@+id/popupwindow_Jan"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="一月份"
android:gravity="center"
/>
<TextView
android:id="@+id/popupwindow_Feb"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="二月份"
android:gravity="center"
/>
<TextView
android:id="@+id/popupwindow_Mar"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="三月份"
android:gravity="center"
/>
</LinearLayout>
</RelativeLayout>
</LinearLayout>第三步:在Activity寫代碼
public void onClick(View v) {
switch (v.getId()) {
case R.id.home_travel_modes_yuefen_textview:
showPopupWindow(v);
break;
case R.id.popupwindow_Jan:
showToastMsg("一月份");
break;
case R.id.popupwindow_Feb:
showToastMsg("二月份");
break;
default:
break;
}
public void showPopupWindow(View v){
View contentView = LayoutInflater.from(HomeTravelModesActivity.this).inflate(R.layout.home_popuplayout, null);
TextView JanText = (TextView)contentView.findViewById(R.id.popupwindow_Jan);
TextView FebText = (TextView)contentView.findViewById(R.id.popupwindow_Feb);
TextView MarText = (TextView)contentView.findViewById(R.id.popupwindow_Mar);
JanText.setOnClickListener(this);
FebText.setOnClickListener(this);
MarText.setOnClickListener(this);
final PopupWindow popupWindow = new PopupWindow(contentView,
LinearLayout.LayoutParams.MATCH_PARENT, 300, true);
popupWindow.setTouchable(true);
// popupWindow.setTouchInterceptor(new View.OnTouchListener() {
//
// @Override
// public boolean onTouch(View v, MotionEvent event) {
//
// Log.i("mengdd", "onTouch : ");
//
// return false;
// // 這里如果返回true的話,touch事件將被攔截
// // 攔截后 PopupWindow的onTouchEvent不被調(diào)用,這樣點擊外部區(qū)域無法dismiss
// }
// });
// 如果不設(shè)置PopupWindow的背景,無論是點擊外部區(qū)域還是Back鍵都無法dismiss彈框
// 我覺得這里是API的一個bug
popupWindow.setBackgroundDrawable(getResources().getDrawable(
R.mipmap.ic_launcher));
// 設(shè)置好參數(shù)之后再show
popupWindow.showAsDropDown(v);
}注:
若在Activity的onCreate()方法中直接寫彈出PopupWindow()方法報錯,因為Activity沒有完全啟動是不能彈出PopupWindow的,那我們只需要在Activity完全啟動后在彈出PopupWindow就行了。
重寫一下onWindowFocusChanged()方法:
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
//彈出PopupWindow的具體代碼
}上述就是小編為大家分享的Popupwindow怎么在Android應(yīng)用中使用了,如果剛好有類似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
網(wǎng)站標(biāo)題:Popupwindow怎么在Android應(yīng)用中使用
當(dāng)前地址:http://chinadenli.net/article16/gphhgg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信公眾號、搜索引擎優(yōu)化、網(wǎng)站建設(shè)、App設(shè)計、虛擬主機(jī)、外貿(mào)建站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)