首先 ,android的默认titlebar 是这样的
自己写完可以是这样的(随便一改)
titlebar自己的布局文件想怎么写就怎么写。
我的布局文件这样:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageView
android:id="@+id/image_titilebar"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@drawable/ic_launcher"
></ImageView>
<TextView
android:text="选项"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textSize="20sp"
android:gravity="center_vertical"
/>
</LinearLayout>
activity 文件这样:
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.activity_main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
R.layout.titlebar);
}
}
但是此时并不能正确的运行起来,你需要在androidmanifest文件中对应的activity 添加android:theme = “xxxx”
OK了就