标签:仿微信
仿微信效果,主要是actionbar的一些知识
1.新建actionBar的menu
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" tools:context="com.pangzaifei.weixin.Demo" > <item android:id="@+id/action_search" android:title="查询" android:icon="@drawable/actionbar_search_icon" android:actionViewClass="android.widget.SearchView" android:showAsAction="ifRoom|collapseActionView" /> <item android:id="@+id/action_plus" android:title="添加" android:icon="@drawable/actionbar_add_icon" android:actionProviderClass="com.pangzaifei.weixin.MyActionPlusProvider" android:showAsAction="ifRoom" /> <item android:id="@+id/action_album" android:title="我的相册" android:icon="@drawable/ofm_photo_icon" android:showAsAction="ifRoom" /> <item android:id="@+id/action_album" android:title="我的收藏" android:icon="@drawable/ofm_collect_icon" android:showAsAction="ifRoom" /> <item android:id="@+id/action_album" android:title="我的银行卡" android:icon="@drawable/ofm_card_icon" android:showAsAction="ifRoom" /> <item android:id="@+id/ofm_setting_icon" android:title="设置" android:icon="@drawable/ofm_photo_icon" android:showAsAction="ifRoom" /> <item android:id="@+id/action_album" android:title="意见反馈" android:icon="@drawable/ofm_feedback_icon" android:showAsAction="ifRoom" /> </menu>使用内置的searcharview
<pre name="code" class="java"> android:actionViewClass="android.widget.SearchView"
使用provider,实现微信+号功能
android:actionProviderClass="com.pangzaifei.weixin.MyActionPlusProvider"2.一些注意的地方
/** * 防止更多按钮在一些手机上不显示的问题 */ private void showOverFlowAlawys() { ViewConfiguration configuration = ViewConfiguration.get(this); try { Field field = ViewConfiguration.class .getDeclaredField("sHasPermanentMenuKey"); field.setAccessible(true); field.setBoolean(configuration, Boolean.FALSE); } catch (Exception e) { e.printStackTrace(); } }
@Override public boolean onMenuOpened(int featureId, Menu menu) { if (featureId == Window.FEATURE_ACTION_BAR && menu != null) { if (menu.getClass().getSimpleName().equals("MenuBuilder")) { // 设置显示icon try { Method m = menu.getClass().getDeclaredMethod( "setOptionalIconsVisible", Boolean.TYPE); m.setAccessible(true); m.invoke(menu, true); } catch (Exception e) { e.printStackTrace(); } } } return super.onMenuOpened(featureId, menu); }
<resources> <declare-styleable name="PagerSlidingTabStrip"> <attr name="pstsIndicatorColor" format="color" /> <attr name="pstsUnderlineColor" format="color" /> <attr name="pstsDividerColor" format="color" /> <attr name="pstsIndicatorHeight" format="dimension" /> <attr name="pstsUnderlineHeight" format="dimension" /> <attr name="pstsDividerPadding" format="dimension" /> <attr name="pstsTabPaddingLeftRight" format="dimension" /> <attr name="pstsScrollOffset" format="dimension" /> <attr name="pstsTabBackground" format="reference" /> <attr name="pstsShouldExpand" format="boolean" /> <attr name="pstsTextAllCaps" format="boolean" /> </declare-styleable> </resources>样式微调
<style name="WeixinTheme" parent="android:Theme.Holo.Light.DarkActionBar"> <item name="android:actionBarStyle">@style/WeChatActionBar</item> <item name="android:itemBackground">@drawable/actionbar_bg_selector</item> <item name="android:actionBarItemBackground">@drawable/actionbar_bg_selector</item> <item name="android:itemTextAppearance">@style/WeChatActionBarOverflow</item> <item name="android:actionOverflowButtonStyle">@style/WeChatActionButtonOverflow</item> </style> <style name="WeChatActionBar" parent="@android:style/Widget.Holo.ActionBar"> <item name="android:background">#303537</item> <item name="android:titleTextStyle">@style/WeChatActionBarTitleText</item> </style> <style name="WeChatActionBarTitleText" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title"> <item name="android:textColor">#cfcfcf</item> <item name="android:textSize">17sp</item> </style> <style name="WeChatActionBarOverflow" parent="@android:style/Widget.ActionButton.Overflow"> <item name="android:textSize">16sp</item> </style> <style name="WeChatActionButtonOverflow" parent="android:style/Widget.Holo.ActionButton.Overflow"> <item name="android:src">@drawable/actionbar_more_icon</item> </style>
完整代码下载地址:
http://download.csdn.net/detail/pangzaifei/7672161
仿微信效果,主要是actionbar的一些知识,布布扣,bubuko.com
标签:仿微信
原文地址:http://blog.csdn.net/pangzaifei/article/details/38082021