我有一个似乎无法解决的问题。
protected void onCreate(Bundle savedInstanceState) {
// comments describe what happens
super.onCreate(savedInstanceState);
Boolean customTitleSupported = this.requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
// crash at underneath line
try
{
setContentView(R.layout.myactivity);
}
catch (Exception e)
{
// You cannot combine custom titles with other title features
}
// never gets to underneath line
if customTitleSupported {
this.getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.override_titlebar);
}
}
...
我使用 android-support-v4.jar 库
requestWindowFeature(Window.FEATURE_NO_TITLE); 不会导致任何问题。
...
来自 AndroidManifest.xml 文件
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17"
/>
<application
android:allowBackup="true"
android:icon="@drawable/replace__logo__app_256_256"
android:label="@string/MicAppName"
android:theme="@style/MicTheme"
android:name="com.example.app.MicApp"
>
来自 styles.xml
<style name="AppBaseTheme" parent="android:Theme">
<item name="android:windowNoTitle">false</item>
</style>
来自 my_theme_support.xml
<style name="MicWindowTitleBackground">
<item name="android:background">@android:color/white</item>
<item name="android:padding">0px</item>
</style>
<style name="MicWindowTitleTextAppearance">
<item name="android:textSize">20sp</item>
<item name="android:textStyle">bold|italic</item>
</style>
<style name="MicWindowTitle">
<item name="android:textAppearance">@style/MicWindowTitleTextAppearance</item>
<item name="android:shadowDx">0</item>
<item name="android:shadowDy">0</item>
<item name="android:shadowRadius">5</item>
<item name="android:shadowColor">#1155CC</item>
</style>
来自 my_theme.xml
<style name="MicTheme" parent="AppBaseTheme">
<item name="android:windowTitleSize">44dip</item>
<item name="android:windowTitleBackgroundStyle">@style/MicWindowTitleBackground</item>
<item name="android:windowTitleStyle">@style/MicWindowTitle</item>
</style>
...
最后 override_titlebar.xml
<?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/myTitleLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/replace__logo__app_256_256">
>
</ImageView>
<TextView
android:id="@+id/myTitleText"
android:text="@string/dotdotdot"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
答案 0 :(得分:0)
我错过了我有一个单独的 styles.xml 用于从未使用
的Android手机<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
用
替换它<style name="AppBaseTheme" parent="android:Theme.Light">
让它发挥作用