【问题标题】:Android - Customizing the title barAndroid - 自定义标题栏
【发布时间】:2011-06-01 14:24:22
【问题描述】:

我想为 Android 应用程序自定义标题栏。我有以下布局:

<?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="80dp" <!-- Problem here -->
    android:gravity="center_vertical"
    >

    <ImageView
        android:id="@+id/header"
        android:background="@drawable/windowtitle"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"/>

</LinearLayout>

我在目标活动中也有以下代码:

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        setContentView(R.layout.home);
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);
        ... 
}

我不明白为什么更改android:layout_height 值时标题栏的高度没有变化。

我错过了什么吗?

谢谢!

【问题讨论】:

    标签: android android-layout android-titlebar


    【解决方案1】:

    根据this article,您应该为此创建自定义样式。看看它是否适合你。

    【讨论】:

    • 实际上,我已经阅读并应用了其中的内容......虽然我不明白为什么我们需要提供自定义样式,因为我们有 window_title 布局。 custom_style 为方程式添加了什么?
    【解决方案2】:

    将 layout_height 设置为线性布局的 wrap_content 或 fill_parent

    然后尝试一下

    【讨论】:

    • 我想设置一个自定义高度。此外,在提供图像背景时,图像会被拉伸以填充宽度,因此比例与原始比例不同。
    【解决方案3】:

    你可以使用:

    getWindow().setLayout(50, 50);
    

    当然,这段代码用于设置窗口的宽度和高度

    【讨论】:

      猜你喜欢
      • 2011-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多