Tag: xml

Android Word-Wrap EditText text

I have been trying to get my EditText box to word wrap, but can’t seem to do it. I have dealt with much more complicated issues while developing Android applications, and this seems like it should be a straight-forward process. However, the issue remains, and I have a large text box that is only allowing […]

add back button to action bar

I have been trying to add a back button to the action bar. I want my view to look like this: I want to add the back button in the left of the action bar. I added this code ActionBar actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); but it doesn’t work. How can I fix this?

Create a custom View by inflating a layout?

I am trying to create a custom View that would replace a certain layout that I use at multiple places, but I am struggling to do so. Basically, I want to replace this: <RelativeLayout android:id=”@+id/dolphinLine” android:layout_width=”fill_parent” android:layout_height=”wrap_content” android:layout_centerInParent=”true” android:background=”@drawable/background_box_light_blue” android:padding=”10dip” android:layout_margin=”10dip”> <TextView android:id=”@+id/dolphinTitle” android:layout_width=”200dip” android:layout_height=”100dip” android:layout_alignParentLeft=”true” android:layout_marginLeft=”10dip” android:text=”@string/my_title” android:textSize=”30dip” android:textStyle=”bold” android:textColor=”#2E4C71″ android:gravity=”center”/> <Button android:id=”@+id/dolphinMinusButton” android:layout_width=”100dip” […]

How to add image in a TextView text?

I’ve searched around on Google and came across this site where I found a question similar to mine in which how to include a image in a TextView text, for example “hello my name is [image]”, and the answer was this: ImageSpan is = new ImageSpan(context, resId); text.setSpan(is, index, index + strLength, 0); I would […]

Initialize preferences from XML in the main Activity

This question already has an answer here: Android Preferences: How to load the default values when the user hasn't used the preferences-screen? 5 answers

How to retrieve style attributes programmatically from styles.xml

Currently I’m using either a WebView or a TextView to show some dynamic data coming from a webservice in one of my apps. If the data contains pure text, it uses the TextView and applies a style from styles.xml. If the data contains HTML (mostly text and images) it uses the WebView. However, this WebView […]

Tiled drawable sometimes stretches

I have a ListView whose items have a tiled background. To accomplish this, I use the following drawable xml: <bitmap xmlns:android=”http://schemas.android.com/apk/res/android” android:src=”@drawable/tile” android:tileMode=”repeat” /> Usually, this works. Sometimes, however, the src drawable isn’t tiled, but stretched to fill the entire list item. (I’ve got several different tiles like this, and I use them mixed in […]

Unexpected namespace prefix “xmlns” found for tag LinearLayout

I am having an error in following xml file. “Unexpected namespace prefix “xmlns” found for tag LinearLayout”. I tried the solutions provided in other similar questions also but it didn’t work for me. Same error is occurring in 3 lines where LinearLayout is used. <?xml version=”1.0″ encoding=”utf-8″?> <ScrollView xmlns:android=”http://schemas.android.com/apk/res/android” android:layout_width=”fill_parent” android:layout_height=”wrap_content” android:background=”@drawable/background” > <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” […]

Android: java.lang.ClassCastException: android.widget.imageView cannot be cast to android.widget.textView

I can’t fix this problem on my listview template: i have the error as in the title of my post, but i won’t cast imageview to textview. Here’s my code: <?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=”200dip” android:layout_weight=”1″ android:paddingBottom=”10dip” > <TextView android:id=”@+id/mq” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:layout_alignParentBottom=”true” android:layout_alignParentRight=”true” android:text=”Metri quadri” android:textColor=”#33b5e5″ android:textSize=”14sp” android:textStyle=”bold” /> <TextView android:id=”@+id/citta” android:layout_width=”wrap_content” […]

Lollipop's backgroundTint has no effect on a Button

I have a Button in my Activity, and I’d like it to have my theme’s accent color. Instead of making my own drawables like we had to do pre-Lollipop, naturally I’d like to use the new backgroundTint attribute. <Button android:id=”@+id/btnAddCode” android:layout_width=”match_parent” android:layout_height=”wrap_content” android:backgroundTint=”@color/accent” android:text=”@string/addressInfo_edit_addCode” /> Unfortunately it has no effect, the button stays gray. I […]

Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.