我正在使用粗糙的bottombar并使用XML>>选项卡。我无法导航到底栏中的不同选项卡,我单击特定的图标,而不会出现。请检查并建议。还要让我知道您是否需要其他信息。
mainActivity.java
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.support.annotation.IdRes;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.MenuItem;
import android.widget.Toast;
import com.example.vt.HomeFragment;
import com.roughike.bottombar.BottomBar;
import com.roughike.bottombar.OnTabSelectListener;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
BottomBar bottomBar = (BottomBar) findViewById(R.id.bottomBar);
bottomBar.setOnTabSelectListener(new OnTabSelectListener() {
@Override
public void onTabSelected(@IdRes int tabId) {
if (tabId == R.id.tab_home){
Intent homeIntent = new Intent(MainActivity.this, HomeFragment.class);
startActivity(homeIntent);
} else if (tabId == R.id.tab_gallery){
Toast.makeText(getBaseContext(),"Gallery",Toast.LENGTH_SHORT).show();
} else if (tabId == R.id.tab_profile){
Intent profileIntent = new Intent(MainActivity.this, MyProfile.class);
startActivity(profileIntent);
} else if(tabId == R.id.tab_location){
Intent locationIntent = new Intent(MainActivity.this, LocationFragment.class);
startActivity(locationIntent);
}
}
});
}
}
dockike bottombar被弃用。建议使用bottomNavigationView。