【问题标题】:Getting double custom titlebar获取双自定义标题栏
【发布时间】:2015-03-21 14:43:17
【问题描述】:

我在下面得到了两个标题栏,我设计了一个带有图像和文本的自定义标题栏,并使用 styles.xml 来设置主题。对于两个不同文本的屏幕,我有相同的标题栏。

代码如下

public class ReminderActivity extends Activity {
    Context context;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        setContentView(R.layout.reminderlayout);
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.reminderlayout);
        ArrayList<GetReminder> list = (ArrayList<GetReminder>) getIntent().getSerializableExtra("reminderList");
        System.out.println("size is >>>"+list.size());
    }
}

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="35dip"
    android:gravity="center_vertical"
    android:orientation="horizontal"
    android:background="@drawable/formheader">
    <ImageView
        android:id="@+id/header"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/ic_launcher"/>
    <TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Reminder Messages"
        android:textColor="@android:color/black"
        android:textStyle="bold" />
</LinearLayout>

清单

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.loginscreen"
    android:versionCode="1"
    android:versionName="1.0" >
    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />
    <uses-permission android:name="android.permission.INTERNET" />
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name="com.example.sampleapp.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.example.sampleapp.ItemActivity"
            android:theme="@style/TitleBarTheme" />
        <activity
            android:name="com.example.sampleapp.ReminderActivity"
            android:theme="@style/TitleBarTheme" >        </activity>
    </application>
</manifest>

和 style.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="titleBarHeading" parent="@android:style/TextAppearance">
        <item name="android:textSize">17sp</item>
        <item name="android:textStyle">bold</item>
        <item name="android:textColor">#444444</item>
    </style>
        <style name="CustomWindowTitleBarBG">
            <item name="android:background">#323331</item>
        </style>
        <style name="TitleBarTheme" parent="android:Theme">
            <item name="android:windowTitleSize">35dip</item>
            <item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBarBG</item>
        </style>
</resources>

【问题讨论】:

  • 分享你的 R.layout.reminderlayout 布局
  • 没有工作,我没有得到 ow 检查我是否再次充气?
  • 我在我的问题中添加了
  • @Fahim 是的,你是对的,它的膨胀问题是正确的,我删除了 getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.reminderlayout); ,,但我无法设置背景颜色除了标题栏外屏幕为白色

标签: android


【解决方案1】:

setContentView(R.layout.reminderlayout); getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.reminderlayout);

您对内容视图和标题使用相同的布局文件。为两者创建单独的布局文件

【讨论】:

猜你喜欢
  • 2012-12-21
  • 1970-01-01
  • 1970-01-01
  • 2020-09-24
  • 2019-01-05
  • 2011-03-10
  • 2023-03-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多