set size of android.R.layout.simple_dropdown_item_1line - android

I am new to android and I made an auto - complete textview and it is working , but my problem is the text size in the android.R.layout.simple_dropdown_item_1line is bigger than simple_dropdown_item_1line .
So is there a way that I can set the text size or set the size of the android.R.layout.simple_dropdown_item_1line ? .
Thanks in advance

Create a custom layout, or copy android.R.layout.simple_dropdown_item_1 contents create a new xml and pass this xml to AutoCompleteTextView
sample:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/autoComplete"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="10sp"
/>
</LinearLayout>

srikanth gr's answer is outdated. This answer is best.
What is "android.R.layout.simple_list_item_1"?
A link to the file in github is:
https://github.com/android/platform_frameworks_base/blob/master/core/res/res/layout/simple_dropdown_item_1line.xml

Related

How to add a spacing between text and underline in android?

I have defined text of a textview as -
<string name="text"><u>this is my text</u></string>
I needed some space between the text and the underline, so I added lineSpacingExtra="2dp" to the textview, but it is not working.
Can anyone tell how to achieve this?
I need to support API 14 till 21. The above test was done on API 21.
I spent a great deal of my time on this question and here are my findings!
Firstly, To increase the spacing between the text and underline in css you need to use styles and unfortunately Android TextView does not support style tag when using Html.fromHtml(). Unfortunately even span tag is not supported (otherwise that could have been used). To see the entire list of tags supported check the HTML Tags Supported By TextView blog.
Now since we know the basic simple implementation wouldn't work, the only other way remaining is to fake it (fool the user!). In your xml layout where you have the TextView add a View below it with the following properties.
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/text"
android:textSize="20sp"/>
<View
android:id="#+id/underlineView"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_alignEnd="#+id/textView"
android:layout_alignLeft="#+id/textView"
android:layout_alignRight="#+id/textView"
android:layout_alignStart="#+id/textView"
android:layout_below="#+id/textView"
android:layout_marginTop="10dp"
android:background="#android:color/holo_red_dark"/>
As you can see the underlineView is emulating the underline. It has its width fixed to the textview above it. You can set its color to whatever you need and importantly you can adjust the spacing using the android:layout_marginTop property. Hope this helps!
My suggestion is to remove the underline from the text string entirely because you can't customize the spacing from there. After that, you have a few options. One option is to use the #drawable feature as discussed in the following link: http://www.quora.com/How-do-I-design-edit-text-view-with-bottom-border-alone-in-Android-and-edit-text-view-with-some-special-symbol-like-below-image
If you want a quick and easy "hack" then go to the layout XML for your activity where your TextView is created. Wrap your TextView in a LinearLayout as follows:
<LinearLayout
android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_width="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/text"
android:layout_marginBottom="2dp" />
<TextView
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#color/underline" />
</LinearLayout>
The first TextView is where your text ("this is my text") is displayed so you can adjust the "layout_marginBottom" to whatever spacing you need between your text and the underline. The second TextView acts as your underline so to adjust its thickness you can change the "layout_height" value.
The final step to making this work is to go into your "values" folder in your project and create a new XML file named "colors.xml". The entire contents for this example are below:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="underline">#333333</color>
</resources>
Simply change the hex color value in this XML file to customize the underline color to your choice.

duplicate attributes android xml

Apparently I have duplicate attributes but cannot spot this, I have gone through the XML line by line but cannot see what's wrong. I have tried to clean, build and have also closed eclipse and opened it again. Also this is a new xml file I created in layout as I wanted to change the text displayed within listview instead of using the standard one
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/text1"
android:layout_height="0dp"
android:layout_width ="fill_parent"
android:textSize="20sp"
android:paddingLeft="6dp"
android:paddingRight="6dp"
android:gravity="center">
</TextView>
Here is a screenshot of where the error is pointing to
SCREENSHOT
ok, it is just an assumption, but the id "text1" is used by android System listview to refer to the internal build textview. Just use another id like
android:id="#+id/my_textview_1"
I guess problem is this line: android:id="#android:id/text1"
change it with this android:id="#+id/text1"

Text clipping inside ListPopupWindow on Android

I have a ListPopupWindow defined as below in my Android application.
ListPopupWindow listPopupWindow;
listPopupWindow = new ListPopupWindow(RootView.this);
listPopupWindow.setAdapter(new ArrayAdapter<String>(RootView.this,
R.layout.push_list_item, pushMessages));
listPopupWindow.setAnchorView(bEvents);
listPopupWindow.setWidth(300);
listPopupWindow.setHeight(400);
listPopupWindow.setModal(true);
listPopupWindow.show();
The XML for the layout referenced above is given below..
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FF0000"
android:paddingLeft="6dp"
android:textSize="12sp"
android:maxLines="3"
android:lines="3"
android:ellipsize="end"
android:textStyle="bold" />
When I get a text that is larger in size, the text just seems to clip as opposed to wrap, even though I have specified the correct attributes inside the XML. Can anyone help me understand what is going on here, and propose a solution for my problem.
Thanks..
The main problem you should get with your xml file that it's not possible to have >2 lines + ellipsize.
You should implement you own EllipsizeTextView to support real multiline ellipsized textview.
You could find an example here and here.
Also you could find this bug here.

Android nested layout

I am developing my first Android app. Although I have 15 years of Java software development experience, Android is new to me. My desired look is a background image with other images on top of it, as well as labels and phone numbers. It seems like the best way to accomplish this is a Linear Layout for the background image, with a nested layout for the other fields on top of that. I have searched online and cannot find any sample code on how to accomplish this. Any recommendations would be greatly appreciated. Thanks in advance.
What are you using to develop? If you are you using Eclipse with the Android SDK this is super easy. Put the desired picture in the appropriate drawable folder, go to the graphical view of layout that corresponds to your activity, on the right side of the screen there is a list of all the properties, find background, then select your picture from drawables. You can also do this from the xml using android:background="#drawable/yourPic". This way you don't have to worry about having things layered on top of it.
I think you should go through followings:
1. http://phandroid.com/2011/05/11/10-tips-for-android-ui-design/
2. http://mobile.tutsplus.com/series/android-user-interface-design/
3. http://coding.smashingmagazine.com/2011/06/30/designing-for-android/
4. http://android-developers.blogspot.in/2011/09/thinking-like-web-designer.html
If I got, something like this can work:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<stuff>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<stuff>
</RelativeLayout>
<stuff>
</RelativeLayout>
I used it in an app, and made the trick.
First of all, RelativeLayout is the best layout to use. It depends on your design.
If your design says to keep all the views either vertically OR horizontally, you can use LinearLayouts in between.
My suggested way:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout android:id="#+id/layout1"
android:layout_width="match_parent"
android:layout_height="wrap_parent"
android:orientation="Horizontal">
<View1 />
<View2 />
</LinearLayout>
</LinearLayout android:id="#+id/layout2"
android:layout_width="match_parent"
android:layout_height="wrap_parent"
android:orientation="Vertical"
android:layout_below="#id/layout1">
<View3 />
<View4 />
</LinearLayout>
</RelativeLayout>
Which will yield you something like this

Android - how to have 'underline'?

How can I achieve this (or something like this)?
Looking for some 'underlines' that will be the width of the element.
Was thinking a drawable but I'm not too sure how that would work with stretching and what not. Thanks.
Edit
Made a new XML file and included it under every title, works great.
<merge xmlns:android="http://schemas.android.com/apk/res/android" >
<View
android:id="#+id/layout_underline"
android:layout_width="match_parent"
android:layout_height="3dip"
android:background="#color/layout_underline" />
</merge>
you can get it by create view in XML as below :
<View
android:layout_width="fill_parent"
android:layout_height="2dp" />
and you can customize it as you need,
hope help you
Create a 9-patch image and set it as the background of your TextViews.
Here's the 9-patch resource page: http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch

Categories

Resources