Android:作为向上按钮的应用程序图标不起作用

标签 android button menu icons

我正在学习 Android 开发者网站上的基本初学者教程。现在,我描述了如何将应用程序图标作为向上按钮(见上文):http://developer.android.com/training/basics/actionbar/adding-buttons.html#UpNav

我输入“getSupportActionBar().setDisplayHomeAsUpEnabled(true);”在我的 Activity onCreate() 方法中,但在我的设备上,我的应用程序没有应用程序图标作为按钮。这是我的 Activity

public class MainActivity extends ActionBarActivity {

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

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);
}

还有我的 list

<?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>

和 Gradle 信息

android {
compileSdkVersion 21
buildToolsVersion "21.1.2"

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

我很困惑,因为我已经为 minSdkVersion 8 使用了正确的方法。

有谁知道,为什么 ma App 不将图标显示为向上按钮?

最好的问候

最佳答案

我遇到了同样的问题 - 启用“将主页显示为向上”会导致出现带有箭头图像的向上按钮。我已通过以下步骤将箭头替换为应用程序图标:

  • /drawable 中使用应用程序图标图像创建一个新的 ImageAsset
  • 在子 Activity 的 OnCreate() 中,添加 2 行:

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

关于Android:作为向上按钮的应用程序图标不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27746636/

相关文章:

android - 无法在我的 Mac 上使用 dex2jar : permission denied

java - Android:MySQL 和 JSON 如此接近?

CSS "Multiple Submit button"问题

php - Knp 菜单包当前项目 Symfony 2

Android SIP 没有来电事件(doubango)

android - 带有 customView 的 Actionbar 有额外的填充,无法删除

python - 如何在 tkinter Canvas 上创建按钮?

button - Scroll Lock 按钮还有用吗?

html - 高级菜单项的问题

android - 带有按钮单击的径向菜单android?