如何在安卓系统中使用PopupMenu的样式?我想要一个灰色背景和一个图标之前的文字。
就像这样:
<style name="GreenText" parent="@android:style/PopupMenu">
<item name="android:textColor">#00FF00</item>
</style>或者我可以在这个线程中构建一个类似的PopupWindow吗?
inflate popup menu items programatically
谢谢。
发布于 2012-12-26 14:13:15
我找不到一种简单的方式来对我的PopupMenu进行样式设计,所以我使用了"PopupWindow“来代替它,向它传递一个列表视图,并按我的意愿对它进行样式化。
popView=layoutInflater.inflate(R.layout.pop_layout, null); // layout with a listview to put in the popup window
lv=(ListView)popView.findViewById(R.id.pop_listview); // then set listview parameters
final PopupWindow contentsopupWindow = new PopupWindow(popView,LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
contentsopupWindow.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.pixel_dot));// set a background so the menu disappears when you click outside it
contentsopupWindow.setTouchable(true);
contentsopupWindow.setFocusable(true);
contentsopupWindow.setOutsideTouchable(true);
contentsopupWindow.setTouchInterceptor(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
contentsopupWindow.dismiss();
return true;
}
return false;
}
});
WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
contentsopupWindow.showAsDropDown(anchorView); https://stackoverflow.com/questions/9671896
复制相似问题