ActionBar中可绘制的后箭头的ID是多少?

问题描述 投票:3回答:2

以下代码导致后箭头出现在ActionBar中:

getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

我正在寻找arrow drawable的资源ID,即android.R.drawable.xxx。我需要这个ID的原因是我可以在我的应用程序的其他地方手动设置相同的箭头(大小和颜色)。

我尝试制作自己的drawable并使用它,但大小与ActionBar中的大小不同。

android android-actionbar android-drawable back up-navigation
2个回答
18
投票

如果项目中有支持库,则可以在应用程序的任何位置创建一个后退按钮,如下所示:

<ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="?attr/homeAsUpIndicator"
        android:background="?attr/selectableItemBackgroundBorderless"/>

具体来说,后箭头的资源是?attr/homeAsUpIndicator


0
投票

工具栏中后退按钮的ID是

android.R.id.home

您可以从onOptionsItemSelected方法对Activity执行操作。

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == android.R.id.home) {
        //Do your task here.
        return true;
    }
    return super.onOptionsItemSelected(item);
}

-3
投票

ActionBar中可绘制的后箭头的ID是android.R.id.home

© www.soinside.com 2019 - 2024. All rights reserved.