0

在我的程序中,有时,我需要隐藏我的自定义标题,但我未能隐藏倾斜的背景图像。我可以很好地隐藏按钮和 Textview。我的代码(xml)如下。

标题 xml:viewimage_slide_title.xml

< RelativeLayout
    android:background="@drawable/iphone_header_bg"
    android:orientation="horizontal"
    android:id="@+id/viewimage_slide_title">

<Button
    android:id="@+id/third_image_button_back"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />
<TextView
    android:id="@+id/third_title_text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>
</RelativeLayout>

样式.xml:

       <color name="transparent">#00000000</color>
       <style name="CustomWindowTitleBackground">
           <item name="android:background">@drawable/iphone_header_bg</item>
        </style>

       <style
            name="title" parent="android:Theme.Light">
           <item name="android:windowTitleSize">50dp</item><item                                                       name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>
          </style>

manifes.xml 。活动。我添加为:

       <activity
        android:name="com.android.camera.third.MianActivity"
        android:configChanges="orientation|keyboardHidden"
        android:label="@string/view_label"
        android:theme="@style/title"
        android:screenOrientation="behind" >

在我的 java(MianActivity) 代码中:

titlebar = (RelativeLayout) findViewById(R.id.viewimage_slide_title);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

setContentView(R.layout.viewimage_slide);

getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
            R.layout.viewimage_slide_title);

在我的其他 java 代码中:我愿意

 MianActivity.titlebar.setVisibility(View.GONE);
4

3 回答 3

1

在您的 XML 中添加一个 ParentLayout:

<RelativeLayout
    android:orientation="horizontal"
    android:layout_heigth="fill_parent"
    android:layout_width="fill_parent">
<RelativeLayout
    android:background="@drawable/iphone_header_bg"
    android:orientation="horizontal"
    android:id="@+id/viewimage_slide_title">

<Button
    android:id="@+id/third_image_button_back"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />
<TextView
    android:id="@+id/third_title_text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>
</RelativeLayout>
</RelativeLayout>

如果你想删除你的 backgroundImage 然后使用,

titlebar.setBackgroundDrawable(null);
titlebar.setVisibility(View.GONE);
于 2013-04-26T07:17:45.413 回答
0

First Of all , what do you mean by custom title bar? Second thing is what i have understood by your code is you want to hide a layout ( viewimage_slide_title.xml) .

For this you simple provide a id to the Relative layout and set visibility gone to the layout rather than the button or textview .

You are able to hide button and text view but failed to hide tilte's background image because background set to relative layout not to button or text.

here is code -

<RelativeLayout
android:background="@drawable/iphone_header_bg"
android:orientation="horizontal"
android:id="@+id/viewimage_slide_title">

<Button
android:id="@+id/third_image_button_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<TextView
android:id="@+id/third_title_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

</RelativeLayout>

Then your main Activity : -

titlebar = (RelativeLayout) findViewById(R.id.viewimage_slide_title);

MianActivity.titlebar.setVisibility(View.GONE);
于 2013-04-26T07:29:15.360 回答
0

我找到了原因,因为我设置了背景的主题(标题)和布局,这是错误的,我改变了我的主题,所以它起作用了。谢谢大家对我的帮助~~这是我在stackoverflow中的第一个问题。

于 2013-04-27T04:07:42.570 回答