行动栏标题隐藏

时间:2015-11-18 20:26:51

标签: java android xml android-actionbar android-toolbar

选择菜单项(如屏幕截图所示)时,文本会填充操作栏标题。然而,标题是从左侧和右侧隐藏的,我正在努力展示比当前显示的标题更多的标题。选择的菜单项是" Equality" " u"显示器。

Screen Shot

如需帮助,请点击我的action_bar.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_gravity="center"
          android:orientation="vertical">
<TextView
    android:id="@+id/title"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginLeft="10dp"
    android:layout_marginStart="10dp"
    android:gravity="left|center"
    android:singleLine="true"
    android:textColor="@android:color/black"
    android:text="Action Bar Title"
    android:textSize="18sp" />

options_menu.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/search"
      android:title="@string/search_title"
      android:icon="@drawable/ic_search"
      android:showAsAction="collapseActionView|ifRoom"
      android:actionViewClass="android.widget.SearchView" />
<!-- android:showAsAction="collapseActionView|ifRoom" -->
<item
    android:id="@+id/action_bookmark"
    android:title="Bookmarks"
    android:orderInCategory="1"
    android:showAsAction="collapseActionView|ifRoom"/>

<item
    android:id="@+id/menu_twitter"
    android:title="Twitter"
    android:orderInCategory="2"
    android:showAsAction="collapseActionView|ifRoom"/>

Controller.java

    mDrawerLayout = (DrawerLayout) mActivity.findViewById(R.id.drawer_layout);
    mDrawerToggle = new ActionBarDrawerToggle(mActivity,                  /* host Activity */
            mDrawerLayout,         /* DrawerLayout object */
            R.string.drawer_open,  /* "open drawer" description */
            R.string.drawer_close  /* "close drawer" description */) {

        /** Called when a drawer has settled in a completely closed state. */
        public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
            mActivity.getActionBar().setTitle(mTitle);
            mActivity.invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }

        /** Called when a drawer has settled in a completely open state. */
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            mActivity.getActionBar().setTitle(mDrawerTitle);
            mActivity.invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }
    };

Activity.java

public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.options_menu, menu);

    menu.findItem(R.id.action_bookmark).setIcon(
            new IconDrawable(this, IconValue.fa_bookmark_o)
                    .colorRes(R.color.aha_white)
                    .actionBarSize());
    menu.findItem(R.id.menu_twitter).setIcon(
            new IconDrawable(this, IconValue.fa_twitter)
                    .colorRes(R.color.aha_white)
                    .actionBarSize());

感谢任何人的帮助!

0 个答案:

没有答案