2015-08-14 72 views
0

我想删除自定义操作栏中的额外填充。我正在使用android SDK 15. enter image description here删除自定义操作栏中的填充

这是我的代码,用于充气操作栏。

protected void onCreate(Bundle savedInstanceState) { 

     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

    android.support.v7.app.ActionBar mActionBar = getSupportActionBar(); 
    mActionBar.setDisplayShowHomeEnabled(false); 
    mActionBar.setDisplayShowTitleEnabled(false); 
    mActionBar.setDisplayHomeAsUpEnabled(false); 
    LayoutInflater mInflater = LayoutInflater.from(this); 

    View mCustomView = mInflater.inflate(R.layout.title, null); 
    mActionBar.setCustomView(mCustomView); 
    mActionBar.setDisplayShowCustomEnabled(true); 
    } 

这是我styles.xml

<!-- Base application theme. --> 
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
    <!-- Customize your theme here. --> 
    <item name="android:actionBarStyle">@style/Widget.Toolbar</item> 

</style> 

<style name="Widget.Toolbar" parent="@style/Widget.AppCompat.Toolbar"> 
    <item name="contentInsetStart">0dp</item> 

</style> 

回答

0

让我们来试试吧!这个对我有用。

mActionBar.setCustomView(mCustomView); 

Toolbar parent =(Toolbar) mCustomView.getParent(); 
parent.setContentInsetsAbsolute(0,0); 
+0

setContentInsetsAbsolute是API级别21我的是15, – deepakgates