Android:从操作栏的自定义布局中删除左边距。

7 浏览
0 Comments

Android:从操作栏的自定义布局中删除左边距。

我正在使用自定义的ActionBar视图,如下面的屏幕截图所示,ActionBar中有一个空的灰色空间。我想要删掉它。

\"enter

我做了什么:

res/values-v11/styles.xml

 

res/values/my_custom_actionbar.xml

    

 


Manifest

    

MainActivity

public void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    ActionBar actionbar = getSupportActionBar();
    actionbar.setDefaultDisplayHomeAsUpEnabled(false);
    actionbar.setDisplayHomeAsUpEnabled(false);
    actionbar.setDisplayShowCustomEnabled(true);
    actionbar.setDisplayShowHomeEnabled(false);
    actionbar.setDisplayShowTitleEnabled(false);
    actionbar.setDisplayUseLogoEnabled(false);
    actionbar.setHomeButtonEnabled(false);
    // Add the custom layout
    View view = LayoutInflater.from(this).inflate(R.layout.actionbar, null, false);
    actionbar.setCustomView(view);
}

我发现最近有一篇帖子指出了最新版本存在问题。我还将ADT和SDK更新到了Android 5。

Android ActionBar\'s custom view not filling parent

我不知道该怎么做。

编辑(部分解决方案):

不能在Android <= API 10上使用。

Android Lollipop, AppCompat ActionBar custom view doesn\'t take up whole screen width

我改变了什么:

使用最新的SDK版本:


添加了一个toolbarStyle

 

 

admin 更改状态以发布 2023年5月21日
0
0 Comments

试试这个:

    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayShowHomeEnabled(false);
    actionBar.setDisplayShowCustomEnabled(true);
    actionBar.setDisplayShowTitleEnabled(false);
    View customView = getLayoutInflater().inflate(R.layout.main_action_bar, null);
    actionBar.setCustomView(customView);
    Toolbar parent =(Toolbar) customView.getParent();
    parent.setPadding(0,0,0,0);//for tab otherwise give space in tab
    parent.setContentInsetsAbsolute(0,0);

0
0 Comments

如果您通过XML添加 Toolbar,只需添加XML属性即可删除内容插图。


0