Android的定制TitleBar中 - 隐藏的文本 [英] Android custom TitleBar - hide text
问题描述
我使用一个标题栏在我的Android应用程序的背景图像。
I am using a titlebar with a background image in my android app.
值/ custom_styles.xml:
values/custom_styles.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="TitlebarBackgroundStyle">
<item name="android:background">@drawable/titlebar</item>
</style>
<style name="Theme.MyCustomTheme" parent="android:Theme">
<item name="android:windowTitleBackgroundStyle">@style/TitlebarBackgroundStyle</item>
<item name="android:windowTitleSize">45dp</item>
</style>
</resources>
布局/ titlebar.xml:
layout/titlebar.xml:
<?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="45dip"
android:gravity="center_vertical">
<ImageView
android:id="@+id/header"
android:src="@drawable/titlebar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
清单:
<application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@style/Theme.MyCustomTheme">
这工作pretty好为止。
This works pretty well so far.
我想现在要做的唯一一件事就是隐藏标题栏的文字...
The only thing I'd like to do now is to hide the text on the titlebar ...
我试过:
<item name="android:textSize">0dp</item>
但没有运气。有什么办法来设置透明度或其他一些财产,让我看到背景图像而不是文字?
but with no luck. Is there any way to set the transparency or some other property that would allow me to see the background image but not the text?
为您的想法谢谢
罗恩
thanks for your thoughts Ron
推荐答案
您可以做到这一点在Java中,没有资源XML,因为标题栏的TextView的是通过在Android的Java源$ C $ C部分线路编程确定
You can do it in Java, not resource xml, since the TextView on the title bar is determined programmatically by some lines in the Android Java source code.
您可以用这种方法隐藏标题栏的TextView的:
You can hide the title bar's TextView in this way :
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
root = (LinearLayout) decorView.getChildAt(0);
FrameLayout titleContainer = (FrameLayout) root.getChildAt(0);
TextView title = (TextView) titleContainer.getChildAt(0);
title.setVisibility(View.GONE);
}
这篇关于Android的定制TitleBar中 - 隐藏的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!