Android仿QQ復(fù)制昵稱效果的實(shí)現(xiàn)方法
背景:
在上一篇文章中,給出了一種復(fù)制QQ效果的方案,今天就來講講換一種方式實(shí)現(xiàn)。主要依賴的是一個開源項(xiàng)目https://github.com/shangmingchao/PopupList。
解決辦法:
PopupList.java的代碼封裝的比較完善,用純java代碼實(shí)現(xiàn)view效果,不需要使用圖片,xml資源文件,引入的話,只需要copy PopupList.java代碼到項(xiàng)目工程中。
剩下的就是調(diào)用了。這里不分析源碼,源碼比較簡單,只講如何使用的。
PopupList popupList = new PopupList(this);
List<String> popupMenuItemList = new ArrayList<>(Arrays.asList("復(fù)制QQ號"));
popupList.bind(tvQQNum, popupMenuItemList, new PopupList.PopupListListener() {
@Override
public boolean showPopupList(View adapterView, View contextView, int contextPosition) {
return true;
}
@Override
public void onPopupListClick(View contextView, int contextPosition, int position) {
ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clipData = ClipData.newPlainText("Label", "10001");
cm.setPrimaryClip(clipData);
}
});
PopupList popupList = new PopupList(this);
List<String> popupMenuItemList = new ArrayList<>(Arrays.asList("復(fù)制"));
popupList.bind(tvUserName, popupMenuItemList, new PopupList.PopupListListener() {
@Override
public boolean showPopupList(View adapterView, View contextView, int contextPosition) {
return true;
}
@Override
public void onPopupListClick(View contextView, int contextPosition, int position) {
ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clipData = ClipData.newPlainText("Label", "天天");
cm.setPrimaryClip(clipData);
}
});
用法很簡單。PopupList支持單個,也支持?jǐn)?shù)組形式的結(jié)構(gòu),如朋友圈點(diǎn)贊的那種效果等。
參考資料:
https://github.com/shangmingchao/PopupList
總結(jié)
以上所述是小編給大家介紹的Android仿QQ復(fù)制昵稱效果的實(shí)現(xiàn)方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
如果你覺得本文對你有幫助,歡迎轉(zhuǎn)載,煩請注明出處,謝謝!
相關(guān)文章
Kotlin startActivity跳轉(zhuǎn)Activity實(shí)現(xiàn)流程詳解
在Android當(dāng)中,Activity的跳轉(zhuǎn)有兩種方法,第一個是利用startActivity(Intent intent);的方法,第二個則是利用startActivityForResult(Intent intent,int requestCode);的方法,從字面上來看,這兩者之間的差別只在于是否有返回值的區(qū)別,實(shí)際上也確實(shí)只有這兩種區(qū)別2022-12-12
Android View教程之自定義驗(yàn)證碼輸入框效果
這篇文章主要給大家介紹了關(guān)于Android View教程之自定義驗(yàn)證碼輸入框效果的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對各位Android開發(fā)者們具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2019-05-05
Android7.0實(shí)現(xiàn)拍照和相冊選取圖片功能
這篇文章主要為大家詳細(xì)介紹了Android7.0實(shí)現(xiàn)拍照和相冊選取圖片功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-07-07
Android自定義下拉刷新控件RefreshableView
這篇文章主要介紹了Android自定義下拉刷新控件RefreshableView,支持所有控件的下拉刷新,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-11-11

