Android實(shí)現(xiàn)微信加號(hào)菜單模式
本文實(shí)例為大家分享了Android實(shí)現(xiàn)微信加號(hào)菜單模式的具體代碼,供大家參考,具體內(nèi)容如下
在模仿微信過程中有一個(gè)加號(hào)菜單啟動(dòng)著實(shí)讓我有點(diǎn)費(fèi)心,因?yàn)槲胰サ袅俗詭У臉?biāo)題欄,想通過OnCreateOptionMenu這段代碼來實(shí)現(xiàn)傳統(tǒng)的Menu顯示顯然是不可能了。所以在自定義創(chuàng)建的狀態(tài)欄里添加了一個(gè)加號(hào)的ImageView,想通過監(jiān)聽ImageView的Onclick來觸發(fā)Popumenu的創(chuàng)建。基本效果與微信相似,細(xì)節(jié)方面還需多多考究。


看具體代碼如下:
1、監(jiān)聽之后創(chuàng)建Popumenu的java代碼:
menuView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PopupMenu popupMenu=new PopupMenu(MainActivity.this,v);
popupMenu.getMenuInflater().inflate(R.menu.menu,popupMenu.getMenu());
/*暴力破解為menu添加icon問題。失敗了。*/
/*if (popupMenu!=null){
try {
Method method=popupMenu.getClass().getDeclaredMethod("setOptionalIconsVisible", Boolean.TYPE);
method.setAccessible(true);
method.invoke(popupMenu,true);
}catch (Exception e){
e.printStackTrace();
}
}*/
popupMenu.show();
}
});
2、Popumenu的xml代碼:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/group"
android:icon="@drawable/icon_menu_group"
android:title="發(fā)起群聊">
</item>
<item android:id="@+id/addfriend"
android:icon="@drawable/icon_menu_addfriend"
android:title="添加朋友">
</item>
<item android:id="@+id/sao"
android:icon="@drawable/icon_menu_sao"
android:title="掃一掃">
</item>
<item android:id="@+id/manney"
android:icon="@drawable/icon_menu_maney"
android:title="收付款">
</item>
<item android:id="@+id/help"
android:icon="@drawable/icon_menu_help"
android:title="幫助與反饋">
</item>
</menu>
但是這并沒有完全解決我的問題,在menu中添加icon圖片資源卻無法實(shí)現(xiàn)。網(wǎng)上有相關(guān)代碼和資料,說是Android將添加圖片資源的變量設(shè)為private類型,并且沒有給開發(fā)者提供外部接口訪問。我也做了相應(yīng)試驗(yàn),但不盡如意。還望高人成功之后能指點(diǎn)一二。
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android實(shí)現(xiàn)微博菜單彈出效果
- Android 側(cè)滑抽屜菜單的實(shí)現(xiàn)代碼
- Android實(shí)現(xiàn)動(dòng)畫效果的自定義下拉菜單功能
- Android實(shí)現(xiàn)上下菜單雙向滑動(dòng)
- Android如何實(shí)現(xiàn)底部菜單固定到底部
- Android實(shí)現(xiàn)衛(wèi)星菜單效果
- Android自定義轉(zhuǎn)盤菜單效果
- Android底部菜單欄(RadioGroup+Fragment)美化
- Android recyclerView橫條指示器實(shí)現(xiàn)淘寶菜單模塊
- android studio 的下拉菜單Spinner使用詳解
- Android仿新浪微博發(fā)送菜單界面的實(shí)現(xiàn)
相關(guān)文章
Android實(shí)現(xiàn)文件上傳和下載倒計(jì)時(shí)功能的圓形進(jìn)度條
這篇文章主要介紹了Android實(shí)現(xiàn)文件上傳和下載倒計(jì)時(shí)功能的圓形進(jìn)度條,需要的朋友可以參考下2017-09-09
Android實(shí)現(xiàn)樹形層級(jí)ListView
這篇文章主要介紹了Android實(shí)現(xiàn)樹形層級(jí)ListView的相關(guān)資料,需要的朋友可以參考下2016-02-02
Android自動(dòng)編輯文本框(AutoCompleteTextView)使用方法詳解
這篇文章主要為大家詳細(xì)介紹了Android自動(dòng)編輯文本框AutoCompleteTextView的使用方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-02-02
Android中Listview點(diǎn)贊功能的實(shí)現(xiàn)
最近一段時(shí)間在研究android方面的知識(shí),利用listview實(shí)現(xiàn)點(diǎn)贊功能,下面小編通過本文給大家介紹下基本思路,需要的朋友可以參考下2016-11-11
基于Manifest.xml中不要出現(xiàn)重復(fù)的uses permission的說明
本篇文章對(duì)Manifest.xml中不要出現(xiàn)重復(fù)的uses permission進(jìn)行了介紹。需要的朋友參考下2013-05-05
android采用FFmpeg實(shí)現(xiàn)音頻混合與拼接剪切
這篇文章主要為大家詳細(xì)介紹了android采用FFmpeg實(shí)現(xiàn)音頻混合與拼接剪切,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-12-12

