我按照这种方式使用Sherlock创建自定义ActionBar 行动吧。我的自定义布局文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_gravity="fill_horizontal" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@color/brown">
<TextView
android:id="@+id/textView1"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="9"
android:text="Add Modules"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/addbutton" />
</LinearLayout>
</RelativeLayout>
下载sherlock库并添加到我的项目中。那我的活动课
公共类MainActivity扩展了SherlockActivity {
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); View actionbar = LayoutInflater.from(this).inflate(R.layout.custom_title_bar, null); getSupportActionBar().setCustomView(actionbar); getSupportActionBar().setDisplayShowHomeEnabled(false); getSupportActionBar().setDisplayShowTitleEnabled(false); getSupportActionBar().setIcon( new ColorDrawable(getResources().getColor(android.R.color.transparent))); getSupportActionBar().setDisplayShowCustomEnabled(true); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getSupportMenuInflater().inflate(R.menu.main, menu); return true; } }
我的新布局中的问题仍然是某些设备可见的黑色旧背景。布局不适合屏幕。
答案 0 :(得分:0)
删除您可以使用的默认背景
getSupportActionBar().setBackgroundDrawable(null);
删除三个点,删除onCreateOptionsMenu