好吧,我正在关注这个创建自定义标题栏的示例:http://thetransientway.com/?p=100。最终的结果应该是喜欢这样的:Android:自定义标题栏崩溃应用程序
title bar http://thetransientway.com/tutorials/android/content/customtitlebar_output.png
的问题是,我打开应用程序的那一刻,它只是崩溃。这就是我现在所拥有的:
活动文件:
package u.nav.it;
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
public class UNavitActivity extends Activity {
/** 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.custom_title);
}
}
custom_title.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativeLayout1"
android:layout_width="fill_parent"
android:background="#005BAA"
android:layout_height="50dp">
<Button
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="Button"
android:id="@+id/button1"
android:layout_alignParentRight="true"
android:layout_marginRight="7dp" >
</Button>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="20dp"
android:text="Title Content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/black" />
</RelativeLayout>
custom_style.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CustomWindowTitleBackground">
<item name="android:background">#323331</item>
</style>
<style name="CustomTheme" parent="android:Theme">
<item name="android:windowTitleSize">50dp</item>
<item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>
</style>
</resources>
的main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
</LinearLayout>
清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="u.nav.it"
android:versionCode="1"
android:versionName="1.0" >
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="@string/app_name"
android:name=".CustomTitlebarActivityActivity" android:theme="@style/CustomTheme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
您可以发布LogCat日志吗? – eightx2 2012-02-12 21:42:57
我不使用模拟器。我只是出口并安装在我的手机上进行测试。我的模拟器冻结[2012-02-12 15:46:00 - UNavit]正在等待HOME('android.process.acore')启动...我google了一下但找不到解决方案为了我。 – LiverpoolFTW 2012-02-12 21:47:34