Android自定义操作栏
我有一个问题,我在应用程序中添加了自定义动作栏,但动作栏视图有一个间隙(链接图片中的红色圆圈位置) 主要活动代码:Android自定义操作栏,android,android-actionbar,Android,Android Actionbar,我有一个问题,我在应用程序中添加了自定义动作栏,但动作栏视图有一个间隙(链接图片中的红色圆圈位置) 主要活动代码: public class MainActivity extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVie
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_layout);
getSupportActionBar().setCustomView(R.layout.actionbar_layout);
getSupportActionBar().setDisplayShowCustomEnabled(true);
}
}
actionbar_布局代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0146A3">
<TextView
android:id="@+id/abr_title"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:gravity="center"
android:singleLine="true"
android:textColor="#FFFFFF"
android:textSize="26sp"
android:text="Title"
tools:text="Title"/>
</RelativeLayout>
但如果不使用android支持库,则不会出现此问题。(“MainActivity extands ActionBarActivity”更改为“MainActivity extands Activity”,而“getSupportActionBar()更改为getActionBar()”)使用style.xml设置Actionbar背景
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:actionBarItemBackground">@drawable/bg_actionbar_selected</item>
</style>
<style name="action_bar" parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">@drawable/yourBackgound or color</item>
</style>
@可绘制/bg\u操作栏\u已选定
@可拉深/背部或颜色
让我建议另一种方法:
步骤1:
隐藏你的操作栏。
将此主题用于活动
android:theme="@android:style/Theme.NoTitleBar"
步骤2:
使用自定义相对布局作为操作栏
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="60dp"
android:background="#009ACD">
</RelativeLayout>
只需在style.xml中更新您的主题,然后在上面尝试。告诉我是否有效?谢谢,但它不起作用。比如说,支持库操作栏样式只能使用“Theme.AppCompat”样式。请在这里提及错误。我已经检查过,没有错误。