我想在我的活动中显示一个向上按钮,功能正常,但我无法显示左侧插入符号。相反,它显示了一个丑陋的后箭头。我在我的活动中这样做 -
public class SecondActivity extends ActionBarActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
setTitle(getString(R.string.second));
mToolbar.setTitleTextColor(getResources().getColor(android.R.color.white));
....
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
....
}
}
但我只是看到了这个 -
这是布局xml -
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="org.step.main.SecondActivity">
<android.support.v7.widget.RecyclerView
android:id="@+id/listsecond"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="?attr/actionBarSize"
android:clipToPadding="false"
tools:context=".SecondActivity"
/>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"/>
</FrameLayout>
有什么建议吗?另外,有没有办法将后退按钮的颜色改为白色?
注意:我使用的是主题 - Theme.AppCompat.Light.NoActionBar
答案 0 :(得分:10)
关注this answer,您可以将任何图标显示为白色。
至于左克拉图标,请查看this answer,其中介绍了您需要下载Action Bar Icon Pack的位置。
修改:您想要的图标位于Action Bar Icons/holo_dark/02_navigation_previous_item/
要显示左箭头白色,您可以这样做:
mToolbar.setTitleTextColor(getResources().getColor(android.R.color.white));
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
//Add the following code to make the up arrow white:
final Drawable upArrow = getResources().getDrawable(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
upArrow.setColorFilter(getResources().getColor(android.R.color.white), PorterDuff.Mode.SRC_ATOP);
getSupportActionBar().setHomeAsUpIndicator(upArrow);
请注意,您需要添加以下导入:
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;