我有一个带动作栏的活动。操作栏弹出菜单(单击溢出按钮后出现)应用我定义的样式。 但是我的Activity里面有一个EditText View,它应该通过点击它打开一个弹出菜单。 此PopUp不适用该样式。
我希望有人能帮帮我..
THX !!
主题:
<style name="MyTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- ActionBar -->
<item name="android:actionBarStyle">@style/ActionBar</item>
<item name="android:actionBarTabStyle">@style/ActionBarTabStyle</item>
<item name="android:popupMenuStyle">@style/ActionBarPopupMenu</item>
<item name="android:dropDownListViewStyle">@style/ActionBarDropDownListView</item>
<item name="android:actionBarWidgetTheme">@style/ActionBar.Theme.actionbar.widget</item>
<item name="actionMenuTextColor">@color/mytheme_white_color</item>
<item name="android:actionMenuTextColor">@color/mytheme_white_color</item>
<item name="android:actionDropDownStyle">@style/ActionBarDropDownNav</item>
<item name="android:spinnerDropDownItemStyle">@style/ActionBarDropDownItem</item>
<item name="android:titleTextStyle">@style/ActionBarTextStyle</item>
<item
name="actionBarItemBackground">@drawable/ns_actionbar_selectable_background_selector</item>
<item name="android:actionBarItemBackground">@drawable/ns_actionbar_selectable_background_selector</item>
<!-- Custom Items: -->
<item name="android:editTextStyle">@style/EditTextStyle_singleLine</item>
<item name="android:buttonStyle">@style/ButtonStyle_Default</item>
<item name="android:checkboxStyle">@style/ns_CheckBoxStyle</item>
</style>
样式:
<style name="ActionBarPopupMenu" parent="@android:style/Widget.Holo.Light.ListPopupWindow">
<item name="android:popupBackground">@drawable/menu_dropdown_panel_actionbar</item>
<item name="android:divider">@drawable/ns_linearlayout_list_divider</item>
</style>
<style name="ActionBarDropDownListView" parent="@android:style/Widget.Holo.Light.ListView.DropDown">
<item name="android:listSelector">@drawable/selectable_background_actionbar</item>
<item name="android:divider">@drawable/ns_linearlayout_list_divider</item>
</style>
<style name="ActionBar.Theme.actionbar.widget" parent="@android:style/Theme.Holo">
<item name="android:popupMenuStyle">@style/ActionBarPopupMenu</item>
<item name="android:dropDownListViewStyle">@style/ActionBarDropDownListView</item>
<item name="android:textColor">@color/mytheme_darkblue_color</item>
<item name="android:textAllCaps">true</item>
<item name="android:textSize">@dimen/text_spinner_item</item>
</style>
PopUp ::
中的非工作代码public class LoginActivity extends Activity {
......
userName = (EditText) this.findViewById(R.id.txtUname);
userName.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
showPopupMenu(userName);
}
});
private void showPopupMenu(View v) {
PopupMenu popupMenu = new PopupMenu(LoginActivity.this, v);
popupMenu.getMenuInflater().inflate(R.menu.test, popupMenu.getMenu());
popupMenu
.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
Toast.makeText(LoginActivity.this, item.toString(),
Toast.LENGTH_LONG).show();
return true;
}
});
popupMenu.show();
}
结果: