I want to change the appearance of the profile in the navigation drawer name and e-mail to the name and e-mail user as in the playstore. This is my code of login using MySQL:
LoginActivity.java
@Override
public void onResponse(String response) {
try {
JSONObject jsonObject= new JSONObject(response);
String success = jsonObject.getString("success");
JSONArray jsonArray = jsonObject.getJSONArray("login");
if (success.equals("1")){
for (int i=0; i<jsonArray.length();i++){
JSONObject object= jsonArray.getJSONObject(i);
String name = object.getString("name").trim();
Toast.makeText(LoginActivity.this, "Login Berhasil. \nSelamat Datang : "+name, Toast.LENGTH_SHORT).show();
Intent intent = new Intent(LoginActivity.this,MainActivity.class);
intent.putExtra("name", name);
intent.putExtra("email", email);
startActivity(intent);
loading.setVisibility(View.GONE);
}
}
} catch (JSONException e) {
e.printStackTrace();
loading.setVisibility(View.GONE);
btnLogin.setVisibility(View.VISIBLE);
Toast.makeText(LoginActivity.this, "Error Check Kembali Email dan Password"+e.toString(), Toast.LENGTH_SHORT).show();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
loading.setVisibility(View.GONE);
btnLogin.setVisibility(View.VISIBLE);
Toast.makeText(LoginActivity.this, "Error"+error.toString(), Toast.LENGTH_SHORT).show();
}
My problem just visual from this login to the profile that display name and email on navigation bar.
This is my source of navigation
Nav_drawer.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:background="@color/colorAccent"
android:gravity="bottom"
android:padding="16dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark"
android:layout_height="match_parent"
android:id="@+id/nav">
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@mipmap/ic_launcher_round"/>
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="8dp"
android:text="Your Name"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
/>
<TextView
android:id="@+id/email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Your Email@gmail.com"/>
</LinearLayout>
home.java
public class MainActivity extends AppCompatActivity {
private DrawerLayout drawer;
private TextView name,email;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
name = findViewById(R.id.name);
email = findViewById(R.id.email);
Intent intent = getIntent();
String extraName = intent.getStringExtra("name");
String extraEmail = intent.getStringExtra("email");
name.setText(extraName);
email.setText(extraEmail);
drawer = findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this,drawer,toolbar,R.string.navigation_drawer_open,R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
}
@Override
public void onBackPressed() {
if (drawer.isDrawerOpen(GravityCompat.START)){
drawer.closeDrawer(GravityCompat.START);
}else {
super.onBackPressed();
}
}
}