自定义标题栏 - Android崩溃
问题描述:
我正在尝试为我的应用程序创建自定义标题栏。问题是,如果我进行这些更改,它会在启动时崩溃:自定义标题栏 - Android崩溃
this.requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
this.getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.titlebar);
问题是什么?我搜索了论坛和网络,但找不到答案。谢谢。
答
尝试设置标题栏
this.requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
this.getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.titlebar);
setContentView(R.layout.main);
+0
可悲的是它还是一样瞬间崩溃。 – TutenStain 2012-08-13 18:35:55
答
这对我的作品后,此呼叫的setContentView(...)。在我看来,你有你的XML错误文件
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
R.layout.window_main_title);
}
XML layout.window_main_title:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#323331">
<ImageView
android:id="@+id/header"
android:src="@drawable/ic_launcher_32"
android:paddingLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"/>
<TextView
android:id="@+id/textHeader"
android:textSize="15dp"
android:textColor="#FEFEFE"
android:text="@string/app_name"
android:paddingLeft="5dp"
android:layout_gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></TextView>
</LinearLayout>
+0
谢谢,但这也行不通。同样的问题。我将尝试获取logcat。我在某处读到这可能不适用于Holo? – TutenStain 2012-08-13 21:56:31
发表您的logcat ... – MAC 2012-08-13 18:36:30