android-xml

android - apply selectableItemBackground in xml with support v7

大兔子大兔子 提交于 2019-11-26 07:57:54
问题 even with android support v7 included in my application adding android:background=\"?android:attr/selectableItemBackground\" makes my IDE, Eclipse throw an error (preventing me from compiling), notifying me that selectableItemBackground is only for min Api 11 and up. How do I add this attribute to a background in XML? assume that copying and pasting from a higher library is not a solution 回答1: Since the attribute is defined in a library (support v7), you would use it as a user-defined

Custom attributes in styles.xml

十年热恋 提交于 2019-11-26 07:23:42
问题 I have created a custom widget, and I\'m declaring it in layout.xml. I have also added some custom attributes in attr.xml. However, when trying to declare these attributes in a style in styles.xml, it\'s giving me No resource found that matches the given name: attr \'custom:attribute\'. I have put the xmlns:custom=\"http://schemas.android.com/apk/res/com.my.package\" in all of the tags in styles.xml, including <?xml> , <resources> , and <style> , but it still gives me the same error, that it

Vertical line using XML drawable

為{幸葍}努か 提交于 2019-11-26 06:56:07
问题 I\'m trying to figure out how to define a vertical line (1dp thick) to be used as a drawable. To make a horizontal one, it\'s pretty straightforward: <shape xmlns:android=\"http://schemas.android.com/apk/res/android\" android:shape=\"line\"> <stroke android:width=\"1dp\" android:color=\"#0000FF\"/> <size android:height=\"50dp\" /> </shape> The question is, how to make this line vertical? Yes, there are workarounds, such as drawing a rectangle shape 1px thick, but that complicates the drawable

How to parse same name tag in Android XML DOM Parsing

血红的双手。 提交于 2019-11-26 06:08:50
问题 I am not able to parse my XML here.It returns \"Item\" only. My AndroidActivity cannot be shown as it is very big that\'s why i have only shown the part which is responsible for parsing. My XML Looks like this : <MyResource> <Item>First</Item> <Item>Second</Item> </MyResource> My ActivityClass method: public class ShowItems extends Activity{ ListView lv; ListAdapter adapter; static final String KEY_RESOURCE = \"MyResource\"; // parent node static final String KEY_ITEM = \"Item\"; ArrayList

Add a background image to shape in XML Android

我的梦境 提交于 2019-11-26 06:00:01
问题 How do you add a background image to a shape? The code I tried below but no success: <?xml version=\"1.0\" encoding=\"utf-8\"?> <shape xmlns:android=\"http://schemas.android.com/apk/res/android\" android:shape=\"rectangle\" android:padding=\"10dp\"> //here is where i need to set the image <solid android:color=\"@drawable/button_image\"/> <corners android:bottomRightRadius=\"5dp\" android:bottomLeftRadius=\"5dp\" android:topLeftRadius=\"5dp\" android:topRightRadius=\"5dp\"/> </shape> 回答1: Use

How do you create Preference Activity and Preference Fragment on Android?

半腔热情 提交于 2019-11-26 04:39:12
问题 As I was following an old tutorial (Créez des applications pour Android -> openclassroom) I got stuck on this deprecated method addPreferencesFromResource(int id) from the PreferenceActivity class. So my question is : What is the new way of creating Preferences in Android ? 回答1: I found this post (What to use instead of “addPreferencesFromResource” in a PreferenceActivity?) that help me understand that you have to go through a PreferenceFragment in order to do it. In the following explanation

Activity Layout: Fragment class: vs android:name attributes

别说谁变了你拦得住时间么 提交于 2019-11-26 04:20:39
问题 I\'ve read the documentation about Fragments in the Android Developer Guide and I\'ve seen that sometimes they specify the class to instantiate with the Fragment tag attribute android:name and sometime they use the class: attribute: <fragment android:name=\"com.example.news.ArticleReaderFragment\" android:id=\"@+id/viewer\" android:layout_weight=\"2\" android:layout_width=\"0dp\" android:layout_height=\"match_parent\" /> <fragment class=\"com.example.android.apis.app.FragmentLayout

Android : difference between invisible and gone?

放肆的年华 提交于 2019-11-26 03:19:30
问题 What is the difference between invisible and gone for the View visibility status? 回答1: INVISIBLE: This view is invisible, but it still takes up space for layout purposes. GONE: This view is invisible, and it doesn't take any space for layout purposes. 回答2: From Documentation you can say that View.GONE This view is invisible, and it doesn't take any space for layout purposes. View.INVISIBLE This view is invisible, but it still takes up space for layout purposes. Lets clear the idea with some

Storing R.drawable IDs in XML array

℡╲_俬逩灬. 提交于 2019-11-26 01:57:01
问题 I would like to store drawable resources\' ID in the form of R.drawable.* inside an array using an XML values file, and then retrieve the array in my activity. Any ideas of how to achieve this? 回答1: You use a typed array in arrays.xml file within your /res/values folder that looks like this: <?xml version="1.0" encoding="utf-8"?> <resources> <integer-array name="random_imgs"> <item>@drawable/car_01</item> <item>@drawable/balloon_random_02</item> <item>@drawable/dog_03</item> </integer-array>

Different resolution support android

偶尔善良 提交于 2019-11-25 22:36:32
问题 Edited Question: Mobile Resolution: I would like to design different screen dpi like following resolutions. 320x480, 480×800, 540x960, 720x1280 (Samsung S3), 1080x1920 (S4, Nexus5,Nexus 5x, Moto G4), 2560 x 1440 (Nexus 6, Nexus 6p, Samsung edge) Tablet Resolution: 480x800 (micromax) , 600x1024 (samsung tab2), 800x1280 (nexus 7), 1200x1920 (new nexus 7), 2048x1536 (nexus 9) I want to use different font sizes depending on the device display resolution. Q1) What is the best way to solve this