Reputation: 1
In my program, sometimes , I need to hide my custom title,but I failed hide the tilte's background image.the button and the Textview I can hide well. my code(xml) as follow.
the title 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>
the style.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>
the manifes.xml . the activity. i add as:
<activity
android:name="com.android.camera.third.MianActivity"
android:configChanges="orientation|keyboardHidden"
android:label="@string/view_label"
android:theme="@style/title"
android:screenOrientation="behind" >
In my java(MianActivity) code:
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);
In my other java code: I do
MianActivity.titlebar.setVisibility(View.GONE);
Upvotes: 0
Views: 452
Reputation: 1
I find the reason , because both the theme (title) and layout I set the backgroud, it is wrong,where I change my theme, so it work. thanks guys for these help me ~~ this is my first question in stackoverflow.
Upvotes: 0
Reputation: 2719
Add one ParentLayout in your XML:
<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>
If you want to remove your backgroundImage then use,
titlebar.setBackgroundDrawable(null);
titlebar.setVisibility(View.GONE);
Upvotes: 1
Reputation: 180
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);
Upvotes: 0