2011-06-01 124 views
2

我想自定义Android应用程序的标题栏。我有以下布局: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

我错过了什么吗?

谢谢!

回答

1

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

+1

实际上,我已经阅读了它,并且应用了其中的内容......虽然我不明白为什么我们需要提供自定义样式,因为我们有'window_title'布局。 custom_style添加到等式中的是什么? – 2011-06-01 14:55:04

0

设置layout_height为线性布局

的WRAP_CONTENT或FILL_PARENT,然后尝试

+0

的宽度和hiegth我想设置一个自定义的高度。同样,当提供图像背景时,图像被拉伸以填充宽度,所以比例与原始图像不相同。 – 2011-06-01 14:59:49

-1

你可以使用:

getWindow().setLayout(50, 50); 
当然

该代码使用设置窗口