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);
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);
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);
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.
Related
I have this custom layout because I want a ListView with TextView below it and I want to handle click on list items so dialog doesn't close. (AlertDialog will show its own message view above its ListView.)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingStart="14dp"
android:paddingEnd="10dp"
>
<ListView
android:id="#+id/optionList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:overScrollMode="never"
android:choiceMode="singleChoice"
android:divider="#null"
/>
<TextView
android:id="#+id/messageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:padding="5dp"
/>
</LinearLayout>
I made a fake setup where I put text in both the dialog's TextView and my layout's. Screenshot of the result.
I even tried putting style="?android:attr/textAppearanceMedium" in #id/messageView in my layout since alert_dialog.xml has it. It made the text larger than the dialog's message. And the color doesn't match, too light (as if it's the Activity's default color).
I even tried using the builder's LayoutInflater, which is what the documentation says to do.
val infl = builder.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
val view = infl.inflate(R.layout.dialog_report_profile, null)
builder.setView(view)
You can always put both style="?android:attr/textAppearanceMedium" AND android:color="#000" at your TextView.
Or, you can just add this to your res/styles.xml:
<style name="DialogMessageText" parent="#android:style/TextAppearance.Medium">
<item name="android:textColor">#android:color/black</item>
</style>
and put this line to your TextView: style="#style/DialogMessageText"
Like overflow menu overlaps the toolbar same way spinner overlaps itself when it is shown drop down item in lollipop and above android version. So I need to place it below the spinner view not over it.
You can use
android:overlapAnchor="false"
This will show the dropdown below the spinner view (Work on api level 21 and higher).
For all api use
android:dropDownVerticalOffset="35dp"
or whatever value that suits your needs.
Recently, I faced the same issue but I have several spinner across the app and I wanted it to look the same without having to add the same property in all of them, so I used the style.xml to customize my spinners as below
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:spinnerStyle">#style/spinner_style</item>
</style>
<style name="spinner_style" parent="Widget.AppCompat.Spinner">
<item name="android:dropDownVerticalOffset">40dip</item>
<item name="overlapAnchor">false</item>
<!--Other customizations-->
</style>
</resources>
android:spinnerMode="dropdown"
android:dropDownVerticalOffset="50dp"
This will show the dropdown below the spinner view.
Ues the following attribute in Spinner
android:dropDownVerticalOffset="35dp"
Here is the below is code for Spinner
<RelativeLayout
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginLeft="45dp"
android:layout_marginRight="3dp"
android:layout_weight=".28"
android:orientation="horizontal">
<Spinner
android:id="#+id/spinner_users"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_gravity="left"
android:layout_marginLeft="5dp"
android:background="#android:color/transparent"
android:dropDownVerticalOffset="35dp"
android:spinnerMode="dropdown" />
<ImageView
android:layout_width="30dp"
android:layout_height="50dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:src="#drawable/drop_down" />
</RelativeLayout>
It depends on where your spinner is located and how many items in the drop down list.
If the spinner layout is at the top of screen, then android:overlapAnchor="false" is enough;
If the spinner layout is around the center of screen with many items, e.g. 60 items, then android:overlapAnchor="false" doesn't satisfy your requirement as no enough space for drop down list; and it's the similar situation when spinner sits at the bottom, but with drop down list above spinner.
I think Spinner isn't a flexible android widget as not many settings available, e.g. drop down height, the first item will be selected when loading data. To achieve the same thing, I think ListPopupWindow is a good replacement. Here is a simple example of it:
layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="match_parent" android:orientation="vertical" android:gravity="center">
<TextView
android:gravity="center_vertical"
android:text="Tap for more options"
android:id="#+id/tv_anchor"
android:layout_margin="20dp"
android:background="#drawable/spinner_bg"
android:layout_width="match_parent"
android:layout_height="40dp"/>
</LinearLayout>
activity:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.act_drop_down)
tvAnchor = findViewById(R.id.tv_anchor)
val popupList = ListPopupWindow(this)
popupList.setAdapter(ArrayAdapter(this, android.R.layout.simple_spinner_item, getData()))
popupList.anchorView = tvAnchor
popupList.width = AbsListView.LayoutParams.WRAP_CONTENT
popupList.height = 100*3
popupList.setOnItemClickListener { parent, view, position, id ->
popupList.dismiss()
}
tvAnchor.setOnClickListener {
popupList.show()
}
}
I want to design a toolbar like:.
I have done most of it but having some problem.
I don't know how to make a divider between the toolbars items and also having no idea how to set a counter variable attached to the action button that increment as order takes place like given in the picture.
Any suggestions?
You can place your layout like below:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/..."
android:showAsAction="always."
android:icon="#drawable/..."
android:title="#string/..."
android:actionLayout="#layout/your_layout_here"/>
or
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/..."
android:showAsAction="always."
android:icon="#drawable/..."
android:title="#string/..."
android:actionViewClass="your_class"/>
where "your_class" - class which inflate and implement your view with separator
Try to create a custom toolbar. Add your views between the toolbar's opening and closing tags.
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="56dip"
android:background="#ff0000">
<!-- the back button -->
<ImageView
android:id="#+id/backButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="left"
android:clickable="true"
android:onClick="onBackButtonClick"
android:paddingLeft="16dip"
android:paddingRight="16dip"
android:src="#drawable/ic_back" />
...
<!-- the devider -->
<View
android:layout_width="1dip"
android:layout_height="match_parent"
android:background="#ffffff" />
<ImageView .../>
</android.support.v7.widget.Toolbar>
I am trying to hide the android action bar, I tried the following in the manifest:
android:theme="#android:style/Theme.NoTitleBar"
and also tried the following in my activity's onCreate method:
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
getActionBar().hide();
setContentView(R.layout.viewpager);
Both work fine and the actionbar is invisible. But the problem is, I cannot use the space that the actionbar left after it disappeared. I mean, if I want to center a widget in the layout vertically, it counts for the space the action bar covers, and then centers the widget in the space left, and so it looks like not centered.Here is the xml file content:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/background"
android:gravity="center_vertical" >
<LinearLayout
android:layout_centerInParent="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/imageview_create_db_first_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#drawable/data" />
<TextView
android:layout_marginTop="10dp"
android:layout_gravity="center_horizontal"
android:id="#+id/textview_create_database"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/create_database"
android:textSize="15sp"
android:textColor="#color/white_text"/>
</LinearLayout>
</RelativeLayout>
So can anyone help me with this?
Thanks
You should either use the no title flag:
requestWindowFeature(Window.FEATURE_NO_TITLE);
Or create your theme and add:
<item name="android:windowNoTitle">true</item>
Your code is fine. I have used similar code in my project. I think the margin:top attribute in your imageview is making it appear below the center.
android:layout_marginTop="20dp"
So remove this line.
I'm trying to duplicate the Overflow Menu dropdown functionality for other ActionBar items. I'm working on a manual implementation of this functionality as I think it has been left out of the environment (likely to force standardisation of UI's). Does anybody know what style / style items are used for the drop down list when you click on the Overflow menu?
EDIT
The overflow button is actually a modified spinner. Here is the style information for it.
<style name="Widget.Holo.Spinner" parent="Widget.Spinner.DropDown">
<item name="android:background">#android:drawable/spinner_background_holo_dark</item>
<item name="android:dropDownSelector">#android:drawable/list_selector_holo_dark</item>
<item name="android:popupBackground">#android:drawable/menu_dropdown_panel_holo_dark</item>
<item name="android:dropDownVerticalOffset">0dip</item>
<item name="android:dropDownHorizontalOffset">0dip</item>
<item name="android:dropDownWidth">wrap_content</item>
<item name="android:popupPromptView">#android:layout/simple_dropdown_hint</item>
<item name="android:gravity">left|center_vertical</item>
</style>
Here is a roundup of what I've cobbled together:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/dropdownContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<LinearLayout
android:id="#+id/leftBuffer"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<LinearLayout
android:layout_width="150dp"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="#+id/actionbarDropdown"
style="#style/Widget.ActionBarDropDown"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:cacheColorHint="#android:color/transparent"
android:entries="#array/sortOptions" />
<LinearLayout
android:id="#+id/bottomBuffer"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<LinearLayout
android:id="#+id/rightBuffer"
android:layout_width="118px"
android:layout_height="match_parent" />
</LinearLayout>
Adding an onClick to an ActionBar item which: adds the above layout as a child to your Activities root ViewGroup gives you the illusion of a drop down.
Adding an onClick to each of the buffers which removes the view from the root ViewGroup allows the drop down to "exit" when you try and move focus.
The styling information for the drop down is:
<item name="android:background">#drawable/menu_dropdown_panel_holo_light</item>
<item name="android:dropDownSelector">#drawable/list_selector_background</item>
The layout for each list item is:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="48dp"
android:textSize="17sp"
android:gravity="right|center_vertical"
style="?android:attr/dropDownItemStyle"
android:ellipsize="marquee"
android:id="#android:id/text1">
</TextView>
This doesn't give a perfect copy of the functionality of an overflow drop down but it's pretty darn close. I am very interested if anyone else knows a way to reproduce this functionality in a more integrated way!
I achive this by having a simple custom view that I put in the ActionBar:
<?xml version="1.0" encoding="utf-8"?>
<ImageButton xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/action_starred"
android:layout_width="wrap_content"
android:layout_height="match_parent"
style="?android:attr/actionButtonStyle"
android:src="#drawable/ic_action_star" />
I then attach a OnClickListener to it in onCreateOptionsMenu() which simply adds a Fragment which takes care of creating a ListPopupWindow and setting the anchor to be the action view. It finds the action view via getActivity().findViewById(R.id.action_starred).
That's simply it, you can set the popup to be modal to make it behave more like a menu. As list items you can use something like android.R.layout.simple_dropdown_item_1line.
This method should work equally well even if you don't put the view in the ActionBar as I do.