我认为标题是不言自明的.performClick()和callOnClick()方法之间的用法有什么不同?看起来它们的工作方式相同,那么为什么View有两种方法呢?
我正在使用Bottom NavigationView并希望以编程方式更改项目.有5个项目,当我选择第4项时,第一项仍然有效.
<android.support.design.widget.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:itemBackground="@color/color_white"
app:itemIconTint="@color/drawer_item"
app:itemTextColor="@color/drawer_item"
android:layout_gravity="start"
app:menu="@menu/nav_bar_menu"/>
Run Code Online (Sandbox Code Playgroud) 导航栏中的第一项保持突出显示。
当我点击导航栏上的其他项目时,内容会发生变化但相应的项目不会高亮显示,只是继续高亮第一个项目。
bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
Fragment fragment=null;
switch (item.getItemId()){
case R.id.number:
fragment=new data();
break;
case R.id.graph:
fragment=new graph();
break;
}
FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.content_drawer, fragment);
fragmentTransaction.commit();
return true;
}
});
Run Code Online (Sandbox Code Playgroud)
这是听众
<RelativeLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
>
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimaryDark"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
app:menu="@menu/navigation" />
<LinearLayout
android:id="@+id/graphlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/navigation"
android:orientation="vertical"
android:gravity="center_vertical">
</LinearLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
这是 xml
<?xml version="1.0" encoding="utf-8"?>
Run Code Online (Sandbox Code Playgroud)
<item
android:id="@+id/number"
android:title="number"
android:checkable="true"/>
<item
android:id="@+id/graph"
android:title="graph" …Run Code Online (Sandbox Code Playgroud)