单击项目时,将导航抽屉滚动到底部

时间:2018-09-20 09:27:42

标签: android navigation-drawer

您好,我是Android新手。我希望在单击项目时将导航抽屉滚动到底部。有可能吗?

Traceback (most recent call last):
  File "gen_tflite_coreml.py", line 32, in <module>
    tflite_model = converter.convert()
  File "/home/rafael/.local/lib/python3.6/site-packages/tensorflow/contrib/lite/python/lite.py", line 335, in convert
    "invalid shape '{1}'.".format(_tensor_name(tensor), shape))
ValueError: None is only supported in the 1st dimension. Tensor 'image' has invalid shape '[None, None, None, 3]'.

如果选择了设置,则我希望导航抽屉向下滚动到底部。怎么做呢?请帮忙。

2 个答案:

答案 0 :(得分:0)

如果我正确理解,id.settings是一个按钮,要在用户单击按钮时添加功能,您应该使用以下代码:

Button settingsBtn = (Button) findViewById(R.id.settings);
            settingsBtn.setOnClickListener(new View.OnClickListener()
            {
                @Override
                public void onClick(View v)
                {
                    --CODE--
                }
            });

答案 1 :(得分:0)

您可以使用onNavigationItemSelected()处理NavigationDrawer个项目。

@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {

    switch (item.getItemId()) {

       case R.id.setting: {
        // do something when clicked
          break;
        }  
    }
    //close navigation drawer
    mDrawerLayout.closeDrawer(GravityCompat.START);
    return true;
}

然后将implements NavigationView.OnNavigationItemSelectedListener添加到您的Activity中:

public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener

记住要在onCreate()中初始化和设置侦听器:

NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);