Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.0k views
in Technique[技术] by (71.8m points)

android - Activity does not open correctly using navigation view

Good morning everyone!

This week I created a new project at Android Studios

It came implemented with a NavigationView, where it replaces the main screen with other fragments

It turns out that i also need to make this side menu open some activitys

The activities open ... But they are transparent and so far I have not been able to resolve this ...

the log is returning the following error:

Unhandled exception while laying out windows
    java.lang.RuntimeException: Unknown animation name: objectAnimator

My MainActivity looks like this:

public class MainActivity extends AppCompatActivity implements CheckConfigurationsListener {

    private AppBarConfiguration mAppBarConfiguration;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        
        DrawerLayout drawer = findViewById(R.id.drawer_layout);
        NavigationView navigationView = findViewById(R.id.nav_view);

        // Passing each menu ID as a set of Ids because each
        // menu should be considered as top level destinations.
        mAppBarConfiguration = new AppBarConfiguration.Builder(
                R.id.nav_home, R.id.nav_gallery, R.id.nav_new_activity)
                .setDrawerLayout(drawer)
                .build();
        NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
        NavigationUI.setupActionBarWithNavController(this, navController, mAppBarConfiguration);
        NavigationUI.setupWithNavController(navigationView, navController);


    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onSupportNavigateUp() {
        NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
        return NavigationUI.navigateUp(navController, mAppBarConfiguration)
                || super.onSupportNavigateUp();
    }


}

The mobile_navigation.xml looks like this:

<?xml version="1.0" encoding="utf-8"?>
<navigation 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/mobile_navigation"
    app:startDestination="@+id/nav_home">

 

    <fragment
        android:id="@+id/nav_home"
        android:name="br.com.rick.medicalpro.ui.home.HomeFragment"
        android:label="@string/menu_home"
        tools:layout="@layout/fragment_home" />

    <fragment
        android:id="@+id/nav_gallery"
        android:name="br.com.rick.medicalpro.ui.gallery.GalleryFragment"
        android:label="@string/menu_gallery"
        tools:layout="@layout/fragment_gallery" />
  
 

    <activity
        android:id="@+id/nav_new_activity"
        android:name="com.navigationcomponentsexample.ui.newactivity.NewActivity"
        android:label="@string/menu_new_activity"
        tools:layout="@layout/activity_new_activity" />
</navigation>

And activity_main_drawer.xml looks like this:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:showIn="navigation_view">

    <group android:checkableBehavior="single">
       
        <item
            android:id="@+id/nav_home"
            android:icon="@drawable/ic_menu_camera"
            android:title="@string/menu_home" />
        <item
            android:id="@+id/nav_gallery"
            android:icon="@drawable/ic_menu_gallery"
            android:title="@string/menu_gallery" />
        <item
            android:id="@+id/nav_new_activity"
            android:icon="@drawable/ic_menu_new_activity"
            android:title="@string/menu_new_activity" />

    </group>
</menu>

The complete error is this:

Unhandled exception while laying out windows
    java.lang.RuntimeException: Unknown animation name: objectAnimator
        at android.view.animation.AnimationUtils.createAnimationFromXml(AnimationUtils.java:128)
        at android.view.animation.AnimationUtils.createAnimationFromXml(AnimationUtils.java:95)
        at android.view.animation.AnimationUtils.loadAnimation(AnimationUtils.java:76)
        at com.android.server.wm.AppTransition.loadAnimationRes(AppTransition.java:438)
        at com.android.server.wm.AppTransition.loadAnimation(AppTransition.java:980)
        at com.android.server.wm.WindowManagerService.applyAnimationLocked(WindowManagerService.java:3547)
        at com.android.server.wm.WindowManagerService.setTokenVisibilityLocked(WindowManagerService.java:4611)
        at com.android.server.wm.WindowManagerService.handleAppTransitionReadyLocked(WindowManagerService.java:9499)
        at com.android.server.wm.WindowManagerService.performLayoutAndPlaceSurfacesLockedInner(WindowManagerService.java:10252)
        at com.android.server.wm.WindowManagerService.performLayoutAndPlaceSurfacesLockedLoop(WindowManagerService.java:9050)
        at com.android.server.wm.WindowManagerService.performLayoutAndPlaceSurfacesLocked(WindowManagerService.java:8997)
        at com.android.server.wm.WindowManagerService.relayoutWindow(WindowManagerService.java:3414)
        at com.android.server.wm.Session.relayout(Session.java:198)
        at android.view.IWindowSession$Stub.onTransact(IWindowSession.java:284)
        at com.android.server.wm.Session.onTransact(Session.java:130)
        at android.os.Binder.execTransact(Binder.java:453)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...