Closed DavaLc closed 6 years ago
大佬,如果只有一个fragment ,像demo里那么写没有问题。 但是多个fragment 还是会出现刚刚的报错。 Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.internal.view.ContextThemeWrapper"
我是这么添加的fragment
/**
//设置底部导航栏的改变 private void setBottomView(int i) { rljIv.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.tab_chat_2)); rljTv.setTextColor(ContextCompat.getColor(this, R.color.color_888888)); ysmIv.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.tab_fans_2)); ysmTv.setTextColor(ContextCompat.getColor(this, R.color.color_888888)); xsIv.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.tab_news_2)); xsTv.setTextColor(ContextCompat.getColor(this, R.color.color_888888)); myIv.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.tab_user_2)); myTv.setTextColor(ContextCompat.getColor(this, R.color.color_888888));
if (i == 0) { rljIv.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.tab_chat_1)); rljTv.setTextColor(ContextCompat.getColor(this, R.color.color_f06868)); } else if (i == 1) { if (mainLll.getVisibility()== View.GONE){ showFooter(); } ysmIv.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.tab_fans_1)); ysmTv.setTextColor(ContextCompat.getColor(this, R.color.color_f06868)); } else if (i == 2) { if (mainLll.getVisibility()==View.GONE){ showFooter(); } xsIv.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.tab_news_1)); xsTv.setTextColor(ContextCompat.getColor(this, R.color.color_f06868)); } else if (i == 3) { if (mainLll.getVisibility()==View.GONE){ showFooter(); } myIv.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.tab_user_1)); myTv.setTextColor(ContextCompat.getColor(this, R.color.color_f06868)); } showFragment(i);
} private int lastPosition = -1;//最后选择的位置 private int curIndex = -1;// 当前选中的左侧菜单的下标 //展示fragment public void showFragment(int index){ if(index == lastPosition) return; FragmentManager fm = getSupportFragmentManager(); FragmentTransaction trx = fm.beginTransaction(); if(curIndex != -1) trx.hide(fragments.get(curIndex));
if (!fragments.get(index).isAdded()) { trx.add(R.id.layFrame, fragments.get(index), "fragment_" + index); } trx.show(fragments.get(index)).commitAllowingStateLoss(); curIndex = index;
}
public void hideFooter(){ mainLll.setVisibility(View.GONE); } public void showFooter(){ mainLll.setVisibility(View.VISIBLE); }
其中HotDramaFragment 就是demo里的VideoFragment,与VideoFragment完全一致
你需要看的是,哪个地方的context转化出现了问题,调用的层级依次是哪些
彻底解决这个问题了。我Activity之前继承的是FragmentActivity,可能是与module里v7包有冲突。改成AppCompatActivity就解决问题了。
大佬,如果只有一个fragment ,像demo里那么写没有问题。 但是多个fragment 还是会出现刚刚的报错。 Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.internal.view.ContextThemeWrapper"
我是这么添加的fragment
/**
//设置底部导航栏的改变 private void setBottomView(int i) { rljIv.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.tab_chat_2)); rljTv.setTextColor(ContextCompat.getColor(this, R.color.color_888888)); ysmIv.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.tab_fans_2)); ysmTv.setTextColor(ContextCompat.getColor(this, R.color.color_888888)); xsIv.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.tab_news_2)); xsTv.setTextColor(ContextCompat.getColor(this, R.color.color_888888)); myIv.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.tab_user_2)); myTv.setTextColor(ContextCompat.getColor(this, R.color.color_888888));
} private int lastPosition = -1;//最后选择的位置 private int curIndex = -1;// 当前选中的左侧菜单的下标 //展示fragment public void showFragment(int index){ if(index == lastPosition) return; FragmentManager fm = getSupportFragmentManager(); FragmentTransaction trx = fm.beginTransaction(); if(curIndex != -1) trx.hide(fragments.get(curIndex));
}
public void hideFooter(){ mainLll.setVisibility(View.GONE); } public void showFooter(){ mainLll.setVisibility(View.VISIBLE); }