我目前正在编写一个包含 BottomNavigationBar(android studio)
的应用程序但是我遇到了一个问题: 我想要切换布局(或至少每个内部的TextViews),
目前导航不仅仅是在单个字符串之间切换。所以我该如何才能使其工作?请给我一个循序渐进的指南,因为我对这一切都很新。
这里有一些代码:
package com.john.doe.mycvasapp;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;
import android.widget.TextView;
public class Personal extends AppCompatActivity {
private TextView mTextMessage;
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
= new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.personal:
mTextMessage.setText(R.string.personal1);
return true;
case R.id.school:
mTextMessage.setText(R.string.school1);
return true;
case R.id.work:
mTextMessage.setText(R.string.work1);
return true;
case R.id.skills:
mTextMessage.setText(R.string.skills1);
return true;
case R.id.lastly:
mTextMessage.setText(R.string.lastly1);
return true;
}
return false;
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_persoenliche_daten);
mTextMessage = (TextView) findViewById(R.id.message);
BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
}
}
感谢所有传入的帮助, 问候,来自互联网的人