ActionView set to an item in support NavigationView not showing

前端 未结 2 1237
耶瑟儿~
耶瑟儿~ 2021-01-15 00:03

I\'m using the support NavigationView in my navigation drawer to display menu of items.



        
2条回答
  •  温柔的废话
    2021-01-15 00:32

    I can change the text of the counter easily enough. However, The text view that I use is within a LinearLayout, and it has an android:id as well (I tried this without the LinearLayout without issue):

     
     
        
    
    

    Given that, I am able to see, access and modify the text view within the main activity using the following :

    TextView countText = (TextView)findViewById(R.id.textCounter);

    countText.setText("6");

    Of course, I'm using a trivial method to calculate the value, just setting it to the value "6", but, I don't know what your counter structure actually looks like, and those are not the main concern of your question.

    The issue with your ability to view the counter number remains a mystery. See my questions above and we'll hammer out that element as well.

    protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
            setSupportActionBar(toolbar);
    
            FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
            fab.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                            .setAction("Action", null).show();
                }
            });
    
            DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
            ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                    this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
            drawer.setDrawerListener(toggle);
            toggle.syncState();
    
            NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
            navigationView.setNavigationItemSelectedListener(this);
    }
    

提交回复
热议问题