在侧滑栏显示用户姓名和角色

my
盛洁 5 years ago
parent 115c90e693
commit 9bda251c5c

@ -9,7 +9,7 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".registe"></activity>
<activity android:name=".RegiteActivity"></activity>
<activity android:name=".SignInActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

@ -27,19 +27,18 @@ import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
private AppBarConfiguration mAppBarConfiguration;
TextView menu_name;
TextView menu_role;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView menu_name = findViewById(R.id.user_name);
TextView menu_role = findViewById(R.id.user_role);
Intent intent = getIntent();
User user;
user = (User) intent.getSerializableExtra("user");
//menu_name.setText(user.getName());
//menu_role.setText(user.getPasd());
setContentView(R.layout.activity_main);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = findViewById(R.id.fab);
@ -62,6 +61,14 @@ public class MainActivity extends AppCompatActivity {
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
NavigationUI.setupActionBarWithNavController(this, navController, mAppBarConfiguration);
NavigationUI.setupWithNavController(navigationView, navController);
if(navigationView.getHeaderCount() > 0) {
View header = navigationView.getHeaderView(0);
TextView menu_name = header.findViewById(R.id.user_name);
TextView menu_role = header.findViewById(R.id.user_role);
menu_name.setText(user.getName());
menu_role.setText(user.getRole());
}
}
@Override

@ -4,7 +4,7 @@ import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class registe extends AppCompatActivity {
public class RegiteActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {

@ -5,7 +5,7 @@ import java.io.Serializable;
public class User implements Serializable{
private String name;
private String pasd;
private String role;
public void setName(String name) {
this.name = name;
}
@ -21,4 +21,12 @@ public class User implements Serializable{
public String getPasd() {
return pasd;
}
public void setRole(String role) {
this.role = role;
}
public String getRole() {
return role;
}
}

@ -4,7 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".registe">
tools:context=".RegiteActivity">
<EditText
android:id="@+id/editText2"
@ -61,4 +61,16 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.461" />
<Button
android:id="@+id/registe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="注册"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.229"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.612" />
</androidx.constraintlayout.widget.ConstraintLayout>

@ -37,7 +37,6 @@
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/fab_margin"
android:paddingTop="@dimen/nav_header_vertical_spacing"
android:text="@string/menu_name"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textSize="24sp" />
@ -46,7 +45,6 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/activity_horizontal_margin"
android:text="@string/menu_role"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textSize="24sp" />

Loading…
Cancel
Save