Ok,
das ist meine MainActivity
Code
public class MainActivity extends AppCompatActivity{
EditText etName, etAge, etUsername;
UserLocalStore userLocalStore;
@Override
protected void onCreate( Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
BottomNavigationView bottomNavigationView = (BottomNavigationView) findViewById(R.id.top_NavView_bar);
BottomNavigationViewHelper.disableShiftMode(bottomNavigationView);
Menu menu = bottomNavigationView.getMenu();
MenuItem menuItem = menu.getItem(0);
menuItem.setChecked(true);
bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener(){
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()){
case R.id.action_profile:
break;
case R.id.action_flight:
startActivity(new Intent(MainActivity.this, FlightActivity.class));
break;
case R.id.action_hotel:
startActivity(new Intent(MainActivity.this, HotelActivity.class));
break;
}
return false;
}
});
userLocalStore = new UserLocalStore(this);
}
@Override
protected void onStart(){
super.onStart();
if(authenticate()==true){
displayUserDetails();
}else{
// startActivity(new Intent(MainActivity.this, Login.class));
}
}
private boolean authenticate(){
return userLocalStore.getUserLoggedIn();
}
private void displayUserDetails(){
User user = userLocalStore.getLoggedInUser();
etUsername.setText(user.username);
etName.setText(user.name);
etAge.setText(user.age);
}
}
Alles anzeigen
Das ist layou.xml dazu
Code
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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"
tools:context=".MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/relLayout"
android:background="@color/colorBackgroud">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="@+id/relLayoutTopBar"
android:layout_alignParentTop="true">
<android.support.design.widget.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/top_NavView_bar"
android:background="@drawable/white_grey_border_top"
app:menu="@menu/top_navigation_menu">
</android.support.design.widget.BottomNavigationView>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/relLayoutMiddle"
android:layout_below="@+id/relLayoutTopBar"
android:layout_centerHorizontal="true">
</RelativeLayout>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
Alles anzeigen
das ist Strings.xml
Code: strings.xml
<resources>
<string name="app_name">SaSiTravel</string>
<string name="title_activity_main">MainActivity</string>
<string name="profile">Profile</string>
<string name="flight">Flight</string>
<string name="hotel">Hotels</string>
<string name="title_activity_hotel">HotelActivity</string>
<string name="oneWay">One-way</string>
<string name="returnTrip">Return trip</string>
<string name="multiCity">Multi-city</string>
<string name="departure">Departure</string>
</resources>
Alles anzeigen
und das ist top_navigation_menu
Code
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
>
<item
android:id="@+id/action_profile"
android:enabled="true"
android:icon="@drawable/ic_profile"
android:title="@string/profile"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/action_flight"
android:enabled="true"
android:icon="@drawable/ic_flight"
android:title="@string/flight"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/action_hotel"
android:enabled="true"
android:icon="@drawable/ic_hotel"
android:title="@string/hotel"
app:showAsAction="ifRoom"/>
</menu>
Alles anzeigen