Changing the style of standard android.R.layout options?

Is it possible to override the default layouts that ship with Android? Is it possible, for example, to make the text smaller for android.R.layout.simple_list_item_checked? Or do I just need to make my own layout for this? Thank you.

+3


source to share


2 answers


You need to create your own layout. To create your own layout and use a standard adapter (such as ArrayAdapter), you must specify the same ID in your custom layout as you would in standard layouts. For example, the TextView in simple_list_item_checked has the id "@android: id / text1" (http://www.devdaily.com/java/jwarehouse/android-examples/platforms/android-2/data/res/layout/simple_list_item_checked.xml. shtml). In your custom layout, you specify this ID. This way you don't need to write a custom adapter. So the best way is to just copy the standard xml layout and change what you wanne change



+1


source


Yes it is. A similar thing is done here (res / values ​​/ styles.xml):

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="ContactLabelTextView">
    <item name="android:layout_width">wrap_content</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:gravity">right</item>
    <item name="android:textSize">14sp</item>
    <item name="android:textColor">@android:color/white</item>
    <item name="android:layout_marginLeft">5dp</item>
    <item name="android:layout_marginRight">5dp</item>
    <item name="android:layout_marginTop">5dp</item>
  </style>
  <style name="questionTableRow">
      <item name="android:layout_width">wrap_content</item>
      <item name="android:layout_height">wrap_content</item>
      <item name="android:layout_margin">5dp</item>
      <item name="android:layout_marginLeft">5dp</item>
      <item name="android:background">@drawable/textview_border</item>
  </style> 
</resources>

      

And then when you want to style an element in the layout file you created (main.xml, res / layout / your_custom_layout.xml):



<?xml version="1.0" encoding="utf-8"?>
    <TableRow
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/questionTableRow"
        style="@style/questionTableRow"

      

Obviously, you want to accomplish this with a textView. I have provided an example of my own code where the textView gets a certain styling. I don't even have a textView style like this, but I pasted where I applied the style to the tableRow so you can see how to apply it to the xml element.

Does this do what you want it to?

0


source







All Articles