每次用户点击popup menu
右下角的button
时,我都会尝试显示card
,但每次点击此{{1}我收到此错误:
android.view.InflateException:二进制XML文件行#0:无法解析索引6处的属性:TypedValue {t = 0x3 / d = 0x6db“res / drawable-xxhdpi-v4 / ic_dots.png”a = 4 r = 0x7f080080}
我认为错误可能是因为我将错误的图标放在错误的文件夹中,所以我尝试将所有图标放在正确的可绘制文件夹中,例如button
,drawable-hdpi
,{{1} },drawable-xxhdpi drawable-mdpi
drawable-xxxhdpi drawable-xhdpi
logcat`,代码如下:
logcat的
,
代码
but it did not work. The
android.view.InflateException: Binary XML file line #0: Failed to resolve attribute at index 6: TypedValue{t=0x3/d=0x6db "res/drawable-xxhdpi-v4/ic_dots.png" a=4 r=0x7f080080}
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.support.v7.view.menu.MenuAdapter.getView(MenuAdapter.java:93)
at android.support.v7.view.menu.MenuPopup.measureIndividualMenuWidth(MenuPopup.java:160)
at android.support.v7.view.menu.StandardMenuPopup.tryShow(StandardMenuPopup.java:169)
at android.support.v7.view.menu.StandardMenuPopup.show(StandardMenuPopup.java:203)
at android.support.v7.view.menu.MenuPopupHelper.showPopup(MenuPopupHelper.java:288)
at android.support.v7.view.menu.MenuPopupHelper.tryShow(MenuPopupHelper.java:175)
at android.support.v7.view.menu.MenuPopupHelper.show(MenuPopupHelper.java:141)
at android.support.v7.widget.PopupMenu.show(PopupMenu.java:233)
at Adapter.CourseAdapter.showPopupMenu(CourseAdapter.java:70)
at Adapter.CourseAdapter.access$000(CourseAdapter.java:26)
at Adapter.CourseAdapter$1.onClick(CourseAdapter.java:56)
at android.view.View.performClick(View.java:5269)
at android.view.View$PerformClick.run(View.java:21556)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5776)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 6: TypedValue{t=0x3/d=0x6db "res/drawable-xxhdpi-v4/ic_dots.png" a=4 r=0x7f080080}
at android.content.res.TypedArray.getLayoutDimension(TypedArray.java:705)
at android.view.ViewGroup$LayoutParams.setBaseAttributes(ViewGroup.java:7094)
at android.view.ViewGroup$MarginLayoutParams.<init>(ViewGroup.java:7275)
at android.widget.FrameLayout$LayoutParams.<init>(FrameLayout.java:506)
at android.widget.FrameLayout.generateLayoutParams(FrameLayout.java:446)
at android.widget.FrameLayout.generateLayoutParams(FrameLayout.java:445)
at android.view.LayoutInflater.inflate(LayoutInflater.java:502)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.support.v7.view.menu.MenuAdapter.getView(MenuAdapter.java:93)
at android.support.v7.view.menu.MenuPopup.measureIndividualMenuWidth(MenuPopup.java:160)
at android.support.v7.view.menu.StandardMenuPopup.tryShow(StandardMenuPopup.java:169)
at android.support.v7.view.menu.StandardMenuPopup.show(StandardMenuPopup.java:203)
at android.support.v7.view.menu.MenuPopupHelper.showPopup(MenuPopupHelper.java:288)
at android.support.v7.view.menu.MenuPopupHelper.tryShow(MenuPopupHelper.java:175)
at android.support.v7.view.menu.MenuPopupHelper.show(MenuPopupHelper.java:141)
at android.support.v7.widget.PopupMenu.show(PopupMenu.java:233)
at Adapter.CourseAdapter.showPopupMenu(CourseAdapter.java:70)
at Adapter.CourseAdapter.access$000(CourseAdapter.java:26)
at Adapter.CourseAdapter$1.onClick(CourseAdapter.java:56)
at android.view.View.performClick(View.java:5269)
at android.view.View$PerformClick.run(View.java:21556)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5776)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
表示错误位于方法public class CourseAdapter extends RecyclerView.Adapter<CourseAdapter.MyViewHolder> {
private Context mContext;
private List<Courses> coursesList;
public CourseAdapter(Context mContext, List<Courses> coursesList) {
this.mContext = mContext;
this.coursesList = coursesList;
}
@Override
public CourseAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.courses_list, parent, false);
return new MyViewHolder(itemView);
}
@Override
public void onBindViewHolder(final CourseAdapter.MyViewHolder holder, int position) {
Courses album = coursesList.get(position);
holder.title.setText(album.getName());
holder.subtext.setText(album.getSubtext());
// loading album cover using Glide library
Glide.with(mContext).load(album.getThumbnail()).into(holder.thumbnail);
holder.overflow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showPopupMenu(holder.overflow);
}
});
}
/**
* Showing popup menu when tapping on 3 dots
*/
private void showPopupMenu(View view) {
// inflate menu
PopupMenu popup = new PopupMenu(mContext, view);
MenuInflater inflater = popup.getMenuInflater();
inflater.inflate(R.menu.menu_course, popup.getMenu());
popup.setOnMenuItemClickListener(new MyMenuItemClickListener());
popup.show();
}
/**
* Click listener for popup menu items
*/
class MyMenuItemClickListener implements PopupMenu.OnMenuItemClickListener {
public MyMenuItemClickListener() {
}
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
switch (menuItem.getItemId()) {
case R.id.action_apply:
Toast.makeText(mContext, "Apply", Toast.LENGTH_SHORT).show();
return true;
default:
}
return false;
}
}
@Override
public int getItemCount() {
return coursesList.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder {
public TextView title, subtext;
public ImageView thumbnail, overflow;
public MyViewHolder(View view) {
super(view);
title = (TextView) view.findViewById(R.id.title);
subtext = (TextView) view.findViewById(R.id.subtext);
thumbnail = (ImageView) view.findViewById(R.id.thumbnail);
overflow = (ImageView) view.findViewById(R.id.overflow);
}
}
}
logcat
的{{1}}文件如下:
menu_course
showPopupMenu(View view)
有人可以帮忙吗?
答案 0 :(得分:0)
尝试使用 -
mContext.getMenuInflater();
而不是
popup.getMenuInflater();