它在我的手机API 27工作正常,但在API 22崩溃
这里是xml文件
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ReportsActivity">
<FrameLayout
android:id="@+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@color/bgBottomNavigation"
app:itemBackground="@color/bgBottomNavigation"
android:foreground="?attr/selectableItemBackground"
app:itemIconTint="@color/nav_color"
app:itemTextColor="@color/nav_color"
app:menu="@menu/navigation" />
这里是MainActivity文件
CoordinatorLayout容器;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_reports);
BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
requestPermission();
loadFragment(new BranchVisitFragment());
}
@Override
public void onFragmentInteraction(Uri uri) {
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu, menu);
return true;
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
switch (item.getItemId()) {
case R.id.menuLogout:
FirebaseAuth.getInstance().signOut();
finish();
startActivity(new Intent(this, LoginActivity.class));
break;
case R.id.refresh:
Fragment f = getSupportFragmentManager().findFragmentById(R.id.frame_container);
if( f instanceof BranchVisitFragment)
BranchVisitFragment.refresh();
if(f instanceof GroupFragment)
GroupFragment.refresh();
break;
case R.id.excel:
Toast.makeText(this,"Creating the Excel Sheet...",Toast.LENGTH_LONG).show();
CreateExcel.createExcel();
break;
我觉得错误是由于这个文件,但我不知道如何使这两个东西在API 22中正常工作
下面是nav_color.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:color="#039BE5" />
<item android:color="#616161" />
</selector>
我已经研究了stackoverflow可能的解决方案,但我无法找到一个
这是gradle文件
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:support-v4:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.itextpdf:itextg:5.5.10'
implementation 'com.android.support:design:28.0.0'
这就是错误:
Caused by: android.view.InflateException: Binary XML file line #16: Error inflating class android.support.design.widget.BottomNavigationView
at android.view.LayoutInflater.createView(LayoutInflater.java:637)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:747)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:810)
at android.view.LayoutInflater.inflate(LayoutInflater.java:508)
at android.view.LayoutInflater.inflate(LayoutInflater.java:418)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.example.aditya.pdf_report.ReportsActivity.onCreate(ReportsActivity.java:59)
at android.app.Activity.performCreate(Activity.java:6093)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2404)
at android.app.ActivityThread.access$900(ActivityThread.java:154)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1315)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5296)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:707)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:611)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:747)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:810)
at android.view.LayoutInflater.inflate(LayoutInflater.java:508)
at android.view.LayoutInflater.inflate(LayoutInflater.java:418)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.example.aditya.pdf_report.ReportsActivity.onCreate(ReportsActivity.java:59)
at android.app.Activity.performCreate(Activity.java:6093)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2404)
at android.app.ActivityThread.access$900(ActivityThread.java:154)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1315)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5296)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:707)
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f070087
at android.content.res.Resources.getValue(Resources.java:1313)
at android.content.res.MiuiResources.getValue(MiuiResources.java:146)
at android.support.v7.content.res.AppCompatResources.isColorInt(AppCompatResources.java:163)
at android.support.v7.content.res.AppCompatResources.inflateColorStateList(AppCompatResources.java:110)
at android.support.v7.content.res.AppCompatResources.getColorStateList(AppCompatResources.java:76)
at android.support.v7.widget.TintTypedArray.getColorStateList(TintTypedArray.java:171)
at android.support.design.widget.BottomNavigationView.<init>(BottomNavigationView.java:148)
at android.support.design.widget.BottomNavigationView.<init>(BottomNavigationView.java:114)
第16行XML
<android.support.design.widget.BottomNavigationView
第59章活动
setContentView(R.layout.activity_reports);
colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#1F618D</color>
<color name="colorPrimaryDark">#000</color>
<color name="colorAccent">#D81B60</color>
<color name="bgBottomNavigation">#fff</color>
<color name="activated">#039BE5</color>
<color name="notactive">#616161</color>
</resources>
menu.xml
<?xml version="1.0" encoding="utf-8"?>
<item
android:id="@+id/menuLogout"
android:title="Logout" />
<item
android:title=""
android:id="@+id/refresh"
android:icon="@drawable/ref"
app:showAsAction="always"/>
<item
android:id="@+id/excel"
android:title="Create Excel"
app:showAsAction="never"/>
4条答案
按热度按时间idfiyjo81#
经过12个小时的严谨思考和思考,我终于找到了解决办法。
我的代码没有任何问题。
在可画文件夹里。
我在v24 drawable文件夹中放置了2个图标PNG,结果它不适用于我检查的API23和API22。
因此,只要把它们放回Drawable文件夹,它的工作就像一个魅力。
谢谢大家的帮助。
vcirk6k62#
在API 26 https://developer.android.com/reference/android/support/design/widget/BottomNavigationView中添加了底部导航
8aqjt8rx3#
我也遇到了同样的问题,通过从底部导航视图XML中删除style属性解决了这个问题。
style="@style/Widget.MaterialComponents.BottomNavigationView"
r3i60tvu4#
我只是改变了底部导航gradle实现的版本,并再次手动添加导航栏在xml文件中,并分配所有属性。成功了