The AutoCompleteTextView displays a ListView in a popup for auto completion. Attached is the image detailing the problem. Just before the first item, there is little white margin. This margin is only visible on the top of the list. This problem is seen on device running 2.3, while on 4.x this problem is not visible.
Can somebody point out the reason for this behavior and a way to fix it.
The code for Layout containing AutoCompleteTextview
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<AutoCompleteTextView
android:id="#+id/menu_search_field"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/textfield_searchview_holo_light"
android:clickable="true"
android:hint="#string/search_hint"
android:imeOptions="actionSearch"
android:lines="1"
android:singleLine="true"
android:textColor="#color/header_text_color"
android:textColorHint="#color/header_hint_text_color"
android:textSize="14dip"/>
</LinearLayout>
The layout defining the item in the Listview.
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:textSize="16sp"
android:textColor="#android:color/white"
android:background="#android:color/black"
android:ellipsize="end"
>
</TextView>
And the drawable for textfield_searchview_holo_light
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:drawable="#drawable/textfield_search_default_holo_dark" />
<item android:drawable="#drawable/textfield_search_default_holo_dark" />
</selector>
Thanks.
Try to add XML attribute to your AutoCompleteTextView:
android:popupBackground="color_what_you_want_to_background"
in your case something like
android:popupBackground="#android:color/black"
Hope, it helps you
Related
I want to apply custom check box design. I followed this post How to apply custom image to checkbox in android, but unfortunately it didn't work for me (in preview screen and also on physical device, I see gray square, which becomes lighter gray on checking). Here is my code:
File where I am applying custom checkbox design (see CheckBox definition) category_spinner_dropdown_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<CheckBox
android:id="#+id/categorySpinnerDropdownItemCheckBox"
android:layout_width="35dp"
android:layout_height="20dp"
android:button="#drawable/custom_checkbox_selector"
android:background="#android:color/transparent"/>
<TextView
android:id="#+id/categorySpinnerDropdownItemTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:textAppearance="#style/toolbar_text_white"/>
</LinearLayout>
<Space
android:layout_width="match_parent"
android:layout_height="7dp"/>
</LinearLayout>
Here is definition of selector: custom_check_box_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/custom_checkbox"
android:state_checked="false"/>
<item android:drawable="#drawable/custom_checkbox_checked"
android:state_checked="true"/>
<item android:drawable="#drawable/custom_checkbox"/>
</selector>
Here are custom_checkbox and custom_checkbox_checked
What am I doing wrong? Thanks!
Solution that works for me is usage of
<androidx.appcompat.widget.AppCompatCheckBox
instead of regular CheckBox. I left everything else unchanged.
With normal layout file, I can set padding top like this
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="?attr/actionBarSize"
>
However, with preference screen, it renders the padding short of some pixels (the action bar is 168 dp, but the padding appears only 144), any idea how to fix this cross-device way. Thanks.
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="?attr/actionBarSize">
When using PreferenceScreen you don't have access to those xml attributes. But what you can do is add this attribute to it:
android:layout="#layout/header_setting"
Then create a XML layout file called in this example "header_settings" you can change the sizes and padding as normal. But applying the id's to the elements the PreferenceScreen knows where the titles goes or icon.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:padding="0dp"
android:layout_height="match_parent">
<ImageView
android:id="#+android:id/icon"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginTop="15dp"
android:layout_marginBottom="15dp"
android:layout_width="40dp"
android:layout_height="40dp" />
<TextView android:id="#+android:id/title"
android:layout_marginLeft="80dp"
android:textColor="#000"
android:layout_marginTop="23dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"/>
</LinearLayout>
And now here is an example on how the PreferenceScreen should look like:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:layout="#layout/pref_screen">
<PreferenceCategory>
<PreferenceScreen
android:icon="#drawable/setting_star"
android:layout="#layout/header_setting"
android:title="Upgrade to Pro!">
</PreferenceScreen>
</PreferenceCategory>
</PreferenceScreen>
Notice how you only have access to the attributes: title, summary, and icon. The layout attribute lets you customize it to whatever you want to do. In the XML you must keep the id's the same since thats how the PreferenceScreen knows thats were to put the title text or the icon image.
I hope this helps!
I have implemented the ripple effect introduced in Lollipop in a ListView. But it is only working for the first item of ListView. I've followed the answers of this question but I'm unable to set a ripple effect.
I have a ripple_background.xml in drawable-v21 folder:
<ripple
xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#android:color/background_dark">
<item>
<shape
android:shape="oval">
<solid android:color="?android:colorAccent" />
</shape>
</item>
</ripple>
The layout my ListView exists in is as following:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ListView
android:id="#+id/listSettings"
android:listSelector="#android:color/transparent"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:divider="#color/price_item_divider"
android:dividerHeight="1dp"
android:drawSelectorOnTop="true"/>
</LinearLayout>
and the items populated inside ListView is as follows (settings_item_row.xml):
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="70dp"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:background="#drawable/ripple_background"
android:padding="16dp" >
<ImageView
android:id="#+id/imageViewIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:paddingRight="10dp" />
<TextView
android:id="#+id/textViewName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/imageViewIcon"
android:paddingRight="10dp"
android:textColor="#android:color/black"
android:textSize="18sp" />
</RelativeLayout>
Thank you for your help!
I faced same issue and found an easy solution to this problem. No need to set any background to any list item or ListView. Just set android:listSelector to your ripple drawable in ListView.
So ListView in my activity look like:
<ListView
android:id="#+id/myListView"
...
android:listSelector="#drawable/ripple" />
and my ripple drawable is defined as :
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#color/rippleColour">
<item android:drawable="#color/backgroundColour"/>
</ripple>
Just had this problem and fixed it. Remove the ripple background drawable from your individual list item views, and then set a background on the ListView itself. As well, add the drawSelector to your list item and remove field from your ListView.
This fix only works for having a single color background for the ListView.
Your List Item View:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="70dp"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:background="#drawable/ripple_background"
android:padding="16dp" >
And Your ListView:
<ListView
android:id="#+id/listSettings"
android:listSelector="#android:color/transparent"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:divider="#color/price_item_divider"
android:dividerHeight="1dp"
android:background="#color/__Your color here__
/>
It happened to me and I changed the clickable value to true than it worked.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
....
android:background="#drawable/touchselector"
android:clickable="true">
....
</LinearLayout>
There is no need to add any background to the layout.
Just leave your layouts as it is. Now concentrate on the ListView
in ListView your can add your own background and you can use ListSelector to apply ripple theme.
By using ListSelector in ListView ripple effect will work on every item in the list and you can give default background to the list items also (separately in list View).
<ListView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/list"
android:scrollbarStyle="outsideInset"
android:background="#fff"
android:listSelector="#drawable/ripp" />
I am working with android app..I created a web view.Now I want to add top and bottom menu bar like header and footer to my app.. my app start with a splash screen..then followed by web view .how can I add these menu to top and bottom of these web view..??? please help me and thanks.
here is my xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/layout"
>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="center"
android:src="#drawable/appinc"
android:visibility="visible"
/>
<WebView android:id="#+id/webview"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:visibility="gone"
/>
<ProgressBar
android:id="#+id/progressBar1"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="114dp" />
</RelativeLayout>
If you are taking about option menu no you cannot change position of menus. See this: https://stackoverflow.com/a/8236188/2741586
However you can actually split you action bar(in 4.0+ versions or older usingmActionBarSherlock). By splitting action bar, menu will appear in both top and button like this: .
If this is what you want: Follow this link
UPDATE:
I found another option! If you want menu like this Google Play
If you want these overflow 3 dot icons: Follow this link.
If none of these suits with your need, you should probably create custom view and modify according to your choice!
Hope this helps!
To apply in your xml try:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="#+id/image"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scaleType="center"
android:src="#drawable/appinc"
android:visibility="visible" />
<LinearLayout
android:id="#+id/bottom_bar"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_alignParentBottom="true"
android:background="#550055" >
</LinearLayout>
<ProgressBar
android:id="#+id/progressBar1"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#id/bottom_bar" />
<WebView
android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#id/progressBar1"
android:layout_below="#id/image"
android:visibility="visible" />
</RelativeLayout>
You should use the android:layout_weight="0dp"
Android gives us many components to make a fast and premium application. TextView, ImageView, etc are the general and important components in android. In this tutorial, you will read to add a border to the top and bottom of an Android view. Border to the android views can be added in several ways. Here, I am going to show the easiest and simplest method to add the border to the Android [TextView, Button] views. So, Just Check this below carefully/.
You need to build an XML drawable file inside res/drawable directory For adding the border. This is worked in android 2.2 and higher.
Adding Border to the Top and Bottom of an Android View
Step By Step Guide to Add Border to the Top and Bottom of an Android View
#1: XML Drawable File
First, you need to create an XML drawable file border_top_bottom.xml in /res/drawable folder like /res/drawable/border_top_bottom.xml and link it to TextView. Your drawable XML file will look like this.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<stroke
android:width="2dp"
android:color="#e10606" />
<solid android:color="#9bce64" />
</shape>
</item>
<item
android:bottom="2dp"
android:top="2dp">
<shape android:shape="rectangle">
<stroke
android:width="2dp"
android:color="#9bce64" />
</shape>
</item>
</layer-list>
border_top_bottom.xml hosted with ❤ by GitHub
#2: XML Layout File
Following is the content of XML layout file where I have added a TextView.
res/layout/top_bottom_border_in_android_view.xml
<?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:layout_margin="16dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Adding Border in Top and Bottom of View" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:background="#drawable/border_top_bottom"
android:padding="30dp"
android:text="Top Bottom Border in TextView"
android:textColor="#000000"
android:textSize="18sp" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:background="#drawable/border_top_bottom"
android:text="Top Bottom Border in Button" />
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:autoLink="web"
android:gravity="center|bottom"
android:text="ViralAndroid.com"
android:textSize="25sp"
android:layout_marginTop="8dp"
android:textStyle="bold" />
</LinearLayout>
top_bottom_border_in_android_view.xml hosted with ❤ by GitHub
#3: Strings.xml File
res/values/strings.xml
<resources>
<string name="app_name">Adding Border to the Top and Bottom of an Android View</string>
</resources>
strings.xml hosted with ❤ by GitHub
Now, run your Adding Border to the Top and Bottom of an Android View application, you will see the border at the top and bottom of TextView.
Good afternoon droids!
I am facing an annoying layout problem to which i have no explanation after hours and hours of investigation... :/. I created a reduced test case which i present here.
I have a simple list item layout.
list item http://www.freeimagehosting.net/4075a.jpg
lis item image link
XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="96dp">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:id="#+id/textView1" android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_centerVertical="true" android:layout_centerHorizontal="true" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="TextView"
android:id="#+id/textView2" android:layout_alignParentTop="true" />
<ImageView
android:layout_width="10dp"
android:layout_height="match_parent"
android:id="#+id/imageView1"
android:src="#drawable/errorindicator"
android:layout_below="#id/textView2" />
</RelativeLayout>
the errorindicator is a red rectangle, which you can see on the image on the left side. The xml looks like that:
<?xml version="1.0" encoding="utf-8"?>
<shape shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#color/ControllingConflictColor" />
<padding android:left="0dp" android:top="0dp"
android:right="0dp" android:bottom="0dp" />
</shape>
The described list item layout works as expected.
Now i try to fill a list view with list items as described above. The result looks like that:
list view with list items http://www.freeimagehosting.net/4cc4b.jpg
list view image link
The corresponding xml:
<?xml version="1.0" encoding="utf-8"?>
<ListView android:id="#+id/listView1" android:layout_width="fill_parent"
android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Preview: listitem=#layout/test -->
</ListView>
As you can see on the image, the red rectangle does not match it's parent in the height anymore as it should. The images are made from the designer, but the same effect is also on the emulator and device. I am developing for API Level 8.
**I'd love if somebody could explain me, why the described layout does not work as expected in a list view. Why does the shape drawable behave different? **
Thank you for your time :)
edit: i have problems embedding the image, i used a link instead, sorry ;(
edit: added xml-drawable tag.
edit: My example can be even made much more easier. I included two text views because it has some similarity to my real layout. You can remove the two text views from the example and there still exists the problem, that the shape drawable in the image view does not match the parents height as defined, if the layout is used in a list view.
Im also finding it hard to get it done using a RelativeLayout. Well try this layout for your row xml. It uses LinearLayout.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:id="#+id/textView2"
android:layout_alignParentTop="true" />
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout android:layout_width="10dip"
android:layout_height="fill_parent"
android:background="#drawable/errorindicator"/>
<TextView android:layout_width="0dip"
android:layout_height="wrap_content"
android:text="TextView" android:layout_weight="1.0"
android:id="#+id/textView1"
android:textAppearance="?android:attr/textAppearanceMedium"
android:gravity="center"/>
</LinearLayout>
</LinearLayout>
Because i guess my desired behaviour is not possible with the give layout manager, i went another way which fits my personal situation.
I have overriden the onDraw method of the RelativeLayout and paint this red rectangle myself (after the layout process finished and the heights are set)...
If you made the asset as a png, you could then 9-patch it and add it as the background of the RelativeLayout