Android: application icon as up button not working

iam after the basic primer on the Android developer site. Now I describe how to bring the application icon as the Up button (see the last text): http://developer.android.com/training/basics/actionbar/adding-buttons.html#UpNav

I put "getSupportActionBar (). SetDisplayHomeAsUpEnabled (true);" in my actions onCreate () Methods, but on my device my application does not have the application icon as a button. Here are my actions

public class MainActivity extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}

and

public class DisplayMessageActivity extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    // Get the message from the intent
    Intent intent = this.getIntent();
    String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);

    // Create the text view
    TextView textView = new TextView(this);
    textView.setTextSize(40);
    textView.setText(message);

    // Set the text view as the activity layout
    setContentView(textView);
}

As well as my manifest

<?xml version="1.0" encoding="utf-8"?>

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".DisplayMessageActivity"
        android:label="@string/title_activity_display_message"
        android:parentActivityName=".MainActivity" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.example.andreas.myapplication.MainActivity" />
    </activity>
</application>

And Gradle Information

android {
compileSdkVersion 21
buildToolsVersion "21.1.2"

defaultConfig {
    applicationId "com.example.andreas.myapplication"
    minSdkVersion 8
    targetSdkVersion 21
    versionCode 1
    versionName "1.0"
}

iam confused because im alredy uses the correct method for minSdkVersion 8.

Does anyone know why the ma app does not show the icon as a button-up?

Regards

+4
4

- " " "" . :

  • ImageAsset /drawable.
  • OnCreate() 2 :

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);                    
    getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_action_home);
    
+3

android: value = "com.example.andreas.myapplication.MainActivity" android: value = ". MainActivity"

, android.support.PARENT_ACTIVITY, :

<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
     android:name="android.support.PARENT_ACTIVITY"
     android:value=".MainActivity" />

: http://programmerguru.com/android-tutorial/how-to-add-up-button-on-action-bar/

+3

, getSupportActionBar().setDisplayHomeAsUpEnabled(true); setContentView(textView); .

EDIT:

, getSupportActionBar().setDisplayHomeAsUpEnabled(true);, . , DisplayMessageActivity. - :

Intent showmessg = new Intent(getApplicationContext(), DisplayMessageActivity.class);
startActivity(showmessg);

, .

: http://developer.android.com/training/basics/actionbar/adding-buttons.html#UpNav

0

, android 5 API 21 .
appcompat v7 rev21, , , , . , , , .

, , appcompat v7 minSdkVersion = "11", getSupportActionBar().setDisplayHomeAsUpEnabled(true); , . rev21, , , minSdkVersion "8", actionBar Up, , . , , google - .. .

"When using Material Themes (the default is API 21 or later), the navigation button (formerly" Home ") takes up the application icon previously. Applications that want to express branding should use the colors of their brands in the action bar and other chrome applications or use instead of their own standard title text. "

0
source

Source: https://habr.com/ru/post/1569739/


All Articles