高仿IOS的Android彈出框
本文實(shí)例為大家分享了Android彈出框的具體代碼,供大家參考,具體內(nèi)容如下
先看一下效果圖,不過(guò)這是網(wǎng)上的圖片。
效果不錯(cuò),就借此拿來(lái)與大伙分享分享。
github源碼地址:https://github.com/saiwu-bigkoo/Android-AlertView.
1.怎么用:添加依賴。
compile 'com.bigkoo:alertview:1.0.3'
2.實(shí)例demo(大家可以根據(jù)需要來(lái)選擇自己需要的框框)。
package com.example.my.androidalertview; import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.inputmethod.InputMethodManager; import android.widget.EditText; import android.widget.Toast; import com.bigkoo.alertview.AlertView; import com.bigkoo.alertview.OnDismissListener; import com.bigkoo.alertview.OnItemClickListener; /** * 精仿iOSAlertViewController控件Demo */ public class MainActivity extends Activity implements OnItemClickListener, OnDismissListener { private AlertView mAlertView;//避免創(chuàng)建重復(fù)View,先創(chuàng)建View,然后需要的時(shí)候show出來(lái),推薦這個(gè)做法 private AlertView mAlertViewExt;//窗口拓展例子 private EditText etName;//拓展View內(nèi)容 private InputMethodManager imm; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); mAlertView = new AlertView("標(biāo)題", "內(nèi)容", "取消", new String[]{"確定"}, null, this, AlertView.Style.Alert, this).setCancelable(true).setOnDismissListener(this); //拓展窗口 mAlertViewExt = new AlertView("提示", "請(qǐng)完善你的個(gè)人資料!", "取消", null, new String[]{"完成"}, this, AlertView.Style.Alert, this); ViewGroup extView = (ViewGroup) LayoutInflater.from(this).inflate(R.layout.alertext_form, null); etName = (EditText) extView.findViewById(R.id.etName); etName.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View view, boolean focus) { //輸入框出來(lái)則往上移動(dòng) boolean isOpen = imm.isActive(); mAlertViewExt.setMarginBottom(isOpen && focus ? 120 : 0); System.out.println(isOpen); } }); mAlertViewExt.addExtView(extView); } public void alertShow1(View view) { mAlertView.show(); } public void alertShow2(View view) { new AlertView("標(biāo)題", "內(nèi)容", null, new String[]{"確定"}, null, this, AlertView.Style.Alert, this).show(); } public void alertShow3(View view) { new AlertView(null, null, null, new String[]{"高亮按鈕1", "高亮按鈕2", "高亮按鈕3"}, new String[]{"其他按鈕1", "其他按鈕2", "其他按鈕3", "其他按鈕4", "其他按鈕5", "其他按鈕6", "其他按鈕7", "其他按鈕8", "其他按鈕9", "其他按鈕10", "其他按鈕11", "其他按鈕12"}, this, AlertView.Style.Alert, this).show(); } public void alertShow4(View view) { new AlertView("標(biāo)題", null, "取消", new String[]{"高亮按鈕1"}, new String[]{"其他按鈕1", "其他按鈕2", "其他按鈕3"}, this, AlertView.Style.ActionSheet, this).show(); } public void alertShow5(View view) { new AlertView("標(biāo)題", "內(nèi)容", "取消", null, null, this, AlertView.Style.ActionSheet, this).setCancelable(true).show(); } public void alertShow6(View view) { new AlertView("上傳頭像", null, "取消", null, new String[]{"拍照", "從相冊(cè)中選擇"}, this, AlertView.Style.ActionSheet, this).show(); } public void alertShowExt(View view) { mAlertViewExt.show(); } private void closeKeyboard() { //關(guān)閉軟鍵盤(pán) imm.hideSoftInputFromWindow(etName.getWindowToken(), 0); //恢復(fù)位置 mAlertViewExt.setMarginBottom(0); } @Override public void onItemClick(Object o, int position) { closeKeyboard(); //判斷是否是拓展窗口View,而且點(diǎn)擊的是非取消按鈕 if (o == mAlertViewExt && position != AlertView.CANCELPOSITION) { String name = etName.getText().toString(); if (name.isEmpty()) { Toast.makeText(this, "啥都沒(méi)填呢", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(this, "hello," + name, Toast.LENGTH_SHORT).show(); } return; } Toast.makeText(this, "點(diǎn)擊了第" + position + "個(gè)", Toast.LENGTH_SHORT).show(); } @Override public void onDismiss(Object o) { closeKeyboard(); Toast.makeText(this, "消失了", Toast.LENGTH_SHORT).show(); } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) { if (mAlertView != null && mAlertView.isShowing()) { mAlertView.dismiss(); return false; } } return super.onKeyDown(keyCode, event); } }
布局文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:orientation="vertical" android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin"> <Button android:text="hey,alert !!!click here~~~" android:layout_width="match_parent" android:layout_marginTop="5dp" android:layout_height="50dp" android:onClick="alertShow1"/> <Button android:text="hey,alert !!!click here~~~" android:layout_width="match_parent" android:layout_marginTop="5dp" android:layout_height="50dp" android:onClick="alertShow2"/> <Button android:text="hey,alert !!!click here~~~" android:layout_width="match_parent" android:layout_marginTop="5dp" android:layout_height="50dp" android:onClick="alertShow3"/> <Button android:text="hey,actionsheet !!!click here~~~" android:layout_width="match_parent" android:layout_marginTop="5dp" android:layout_height="50dp" android:onClick="alertShow4"/> <Button android:text="hey,actionsheet !!!click here~~~" android:layout_width="match_parent" android:layout_marginTop="5dp" android:layout_height="50dp" android:onClick="alertShow5"/> <Button android:text="hey,actionsheet !!!click here~~~" android:layout_width="match_parent" android:layout_marginTop="5dp" android:layout_height="50dp" android:onClick="alertShow6"/> <Button android:text="窗口拓展點(diǎn)這里" android:layout_width="match_parent" android:layout_marginTop="5dp" android:layout_height="50dp" android:onClick="alertShowExt"/> </LinearLayout>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android 多種簡(jiǎn)單的彈出框樣式設(shè)置代碼
- Android實(shí)現(xiàn)可輸入數(shù)據(jù)的彈出框
- Android使用Dialog風(fēng)格彈出框的Activity
- react-native 封裝選擇彈出框示例(試用ios&android)
- Android中自定義PopupWindow實(shí)現(xiàn)彈出框并帶有動(dòng)畫(huà)效果
- Android 仿微信朋友圈點(diǎn)贊和評(píng)論彈出框功能
- android自定義彈出框樣式的實(shí)現(xiàn)方法
- Android仿微信進(jìn)度彈出框的實(shí)現(xiàn)方法
- Android編程實(shí)現(xiàn)仿QQ發(fā)表說(shuō)說(shuō),上傳照片及彈出框效果【附demo源碼下載】
- Android自定義彈出框的方法
相關(guān)文章
iOS開(kāi)發(fā)KVO實(shí)現(xiàn)細(xì)節(jié)解密
這篇文章主要為大家介紹了iOS開(kāi)發(fā)KVO實(shí)現(xiàn)細(xì)節(jié)解密,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-08-08在IOS系統(tǒng)上滾動(dòng)條滾動(dòng)到指定的位置出現(xiàn)空白頁(yè)面的解決方案
這篇文章主要介紹了 在IOS系統(tǒng)上滾動(dòng)條滾動(dòng)到指定的位置出現(xiàn)空白頁(yè)面的解決方案,需要的朋友可以參考下2017-01-01使用Xcode為iOS應(yīng)用項(xiàng)目創(chuàng)建PCH文件的方法及應(yīng)用示例
這篇文章主要介紹了使用Xcode為iOS應(yīng)用項(xiàng)目創(chuàng)建PCH文件的方法及應(yīng)用示例,PCH文件可以保留應(yīng)用的很多的基礎(chǔ)設(shè)置信息以供復(fù)用,需要的朋友可以參考下2016-03-03IOS 下獲取 rootviewcontroller 的版本不同的問(wèn)題解決辦法
這篇文章主要介紹了IOS 下獲取 rootviewcontroller 的版本不同的問(wèn)題解決辦法的相關(guān)資料,希望通過(guò)本文能幫助到大家,讓大家遇到這種問(wèn)題可以解決,需要的朋友可以參考下2017-10-10iOS統(tǒng)計(jì)項(xiàng)目的代碼總行數(shù)
最近一個(gè)項(xiàng)目有段時(shí)間了,不知道怎樣可以統(tǒng)計(jì)出寫(xiě)了多少行代碼,如何處理這個(gè)問(wèn)題呢,下面我們來(lái)探討下。2015-06-06