Ich versuche auf ProfilFragment-Seite zu gehen, aber wenn ich versuche, die Schaltfläche auf der Aktionsleiste zu drücken, geht es LoginActivity, was eine andere unabhängige Aktivität ist. Wie kann ich das durchführen? HierWie gehe ich zu einer anderen Seite, wenn ich die Zurück-Taste in der Aktionsleiste drücke?
ist der Code: Mein SettingsActivity.java
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.DatePicker;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import java.util.Calendar;
public class SettingsActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
Typeface ubuntu_MI = Typeface.createFromAsset(getAssets(), "Ubuntu-MI.ttf");
// Get the ActionBar
android.support.v7.app.ActionBar ab = getSupportActionBar();
// Create a TextView programmatically.
TextView tv = new TextView(getApplicationContext());
// Create a LayoutParams for TextView
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT, // Width of TextView
RelativeLayout.LayoutParams.WRAP_CONTENT); // Height of TextView
// Apply the layout parameters to TextView widget
tv.setLayoutParams(lp);
// Set text to display in TextView
// This will set the ActionBar title text
tv.setText("Ayarlar");
// Set the text color of TextView
// This will change the ActionBar title text color
tv.setTextColor(Color.parseColor("#FFF5EE"));
// Center align the ActionBar title
tv.setGravity(Gravity.CENTER_HORIZONTAL);
// Set the serif font for TextView text
// This will change ActionBar title text font
tv.setTypeface(ubuntu_MI);
// Underline the ActionBar title text
// tv.setPaintFlags(tv.getPaintFlags()| Paint.UNDERLINE_TEXT_FLAG);
// Set the ActionBar title font size
tv.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 24);
// Display a shadow around ActionBar title text
//tv.setShadowLayer(
// 1.f, // radius
// 2.0f, // dx
// 2.0f, // dy
// Color.parseColor("#FF8C00") // shadow color
//);
// Set the ActionBar display option
ab.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
// Finally, set the newly created TextView as ActionBar custom view
ab.setCustomView(tv);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
public boolean onOptionsItemSelected(MenuItem item) {
//Action Bar'daki back butonuna basınca ne yapacağını söylüyoruz.
if (item.getItemId() == android.R.id.home) {
Intent intent = new Intent(getApplicationContext(), ProfileFragment.class);
NavUtils.navigateUpTo(this, intent);
return true;
}
return super.onOptionsItemSelected(item);
}
}
Sie können keine Absicht erstellen, die zu einem Fragment führt, können Sie nur auf Aktivitäten navigieren. – Egor
also, wie kann ich das beheben? –
Erstellen Sie eine Absicht für die Aktivität, die das ProfileFragment enthält. – Egor