Android 操作栏(工具栏)图标
我有一个导航抽屉,为了在操作栏上显示它,我创建了自定义工具栏视图并将其设置为操作栏。现在我有了我无法更改的箭头图标 这是我的基本活动的一部分,我尝试了这些方法,没有任何变化:Android 操作栏(工具栏)图标,android,Android,我有一个导航抽屉,为了在操作栏上显示它,我创建了自定义工具栏视图并将其设置为操作栏。现在我有了我无法更改的箭头图标 这是我的基本活动的一部分,我尝试了这些方法,没有任何变化: protected void onCreateDrawer() { // R.id.drawer_layout should be in every activity with exactly the same id. drawerLayout = (DrawerLayout) f
protected void onCreateDrawer()
{
// R.id.drawer_layout should be in every activity with exactly the same id.
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
Toolbar toolbar = (Toolbar) findViewById(R.id.tool_bar);
setSupportActionBar(toolbar);
drawerToggle = new ActionBarDrawerToggle((Activity) this, drawerLayout, R.drawable.ic_drawer, 0, 0)
{
public void onDrawerClosed(View view)
{
getSupportActionBar().setTitle(R.string.app_name);
}
public void onDrawerOpened(View drawerView)
{
getSupportActionBar().setTitle("Aaaaaaaaaaa");
}
};
drawerLayout.setDrawerListener(drawerToggle);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayUseLogoEnabled(true);
getSupportActionBar().setLogo(R.drawable.ic_drawer);
getSupportActionBar().setDisplayShowTitleEnabled(true);
MainActivity的XML部分,其中我有工具栏,活动的所有内容都设置在框架布局中:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="false">
<!-- The main content view -->
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/tool_bar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary" />
<FrameLayout
android:id="@+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize">
使用工具栏.setTitle(“aaaaaaaaaaaaa”)
而不是
getSupportActionBar().setTitle("Aaaaaaaa");
像这样试试
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/custom_actionbar"
style="@style/ToolBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/transparent"
android:minHeight="@dimen/abc_action_bar_default_height_material">
<TextView
android:id="@+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:textAllCaps="true"
android:textColor="#ffffff"
android:textSize="18sp"
android:textStyle="bold" />
</android.support.v7.widget.Toolbar>
澄清您的问题添加以下行getSupportActionBar()。setDisplayHomeAsUpEnabled(true);getSupportActionBar().setHomeButtonEnabled(true)代码>我已经有这些行了。。。参见代码。我的问题是我无法在actionbar/工具栏上设置任何内容。标题等…请发布一个屏幕截图,让人们看到发生了什么。@HiI'mFrogatto,请参阅编辑,发布SS。
Toolbar mToolbar =(Toolbar) findViewById(R.id.metro_toolbar_actionbar);
TextView mTitle = (TextView) mToolbar.findViewById(R.id.toolbar_title);
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowTitleEnabled(false);
mTitle.setText("Your text");