工具栏左侧增加了额外的空间

时间:2015-08-06 07:20:14

标签: android android-toolbar

我在我的应用中使用自定义工具栏。工具栏在其左侧增加了额外的空间。这是我的Xml文件:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:id="@+id/customActionBar"
    android:layout_height="wrap_content"
    android:background="@color/titleBar">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal">

    <ImageButton
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:id="@+id/leftIcon"
        android:src="@drawable/abc_btn_rating_star_on_mtrl_alpha"
        android:background="@android:color/transparent"
        android:layout_weight="0.2"/>

    <TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:id="@+id/actionTitleText"
        android:text="@string/app_name"
        android:textColor="@color/abc_primary_text_disable_only_material_dark"
        android:textSize="@dimen/text_22sp"
        android:padding="@dimen/size_12dip"
        android:gravity="center_horizontal"
        android:layout_weight="0.6"/>

    <ImageButton
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:id="@+id/rightIcon"
        android:src="@drawable/abc_btn_rating_star_on_mtrl_alpha"
        android:background="@android:color/transparent"
        android:layout_weight="0.2"/>
</LinearLayout>


</android.support.v7.widget.Toolbar>
你能帮帮忙吗? 它从屏幕左边给出一些余量,但我没有给出任何保证金属性。 这是将其扩展为活动的代码:

 @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        super.setContentView(R.layout.activity_main);
        baseViewContent = (LinearLayout) findViewById(R.id.main_activity_content_view);
        viewController = new ViewController(this, baseViewContent);
        activity = this;

        // Set a toolbar to replace the action bar.
        android.support.v7.widget.Toolbar toolbar = (android.support.v7.widget.Toolbar) findViewById(R.id.customActionBar);
        setSupportActionBar(toolbar);

3 个答案:

答案 0 :(得分:6)

使用

override func viewWillAppear(animated: Bool) { super.viewWillAppear(animated) var footerView = self.tableView.tableFooterView! as UIView var frame = footerView.frame frame.size.height = 30 footerView.frame = frame self.tableView.tableFooterView! = footerView }

删除多余的空间。

参考:https://stackoverflow.com/a/27309500

答案 1 :(得分:0)

解决方案是

toolbar.setContentInsetsAbsolute(0,0);

答案 2 :(得分:0)

对于像我这样的其他人:我没有看到工具栏中的标题,因为它与背景颜色相同。如果需要,您可以使用 getSupportActionBar().setDisplayShowTitleEnabled(false)

删除它
相关问题