I have the following pseudo layout:
<RelativeLayout>
<ACustomView />
<AnotherCustomView />
</RelativeLayout>
I have TextViews in both of the custom views (inflated from XML). How can i set
style properties (eg. textColor) for every TextView in the first custom view? For example i want every TextView to be red which are in the first custom view.
I don't think that this is possible.
If you don't want to much typing you can define your own style and add it to each textview or you can create your own textview class where style attributes are set.
For an example use this question/answer:
Setting global styles for Views in Android
I hope i could help you
Cu
JackZ
Related
I have a LinearLayout that has 2 children: a ImageView aligned left and a TextView aligned right.
I've set the background of the LinearLayout to be a #drawable XML resource that has two <item> tags. One of them has android:state_pressed="true". Also, the LinearLayout has android:clickable="true".
When the LinearLayout is clicked it correctly changes its background to the android:state_pressed style, but clicking on one of its children doesn't propagate the click action up to the LinearLayout.
Is there a way to easily achieve a click state on the parent view when a child view is clicked?
Dont use Both as it will give Exception
Use this to your parent
android:addStatesFromChildren="true"
Or add in your child views
`android:duplicateParentState="true"`
Hope it helps
not sure if it works for your specific implementation, but a very easy way of achieving this "complex" button is by making a normal button and using android:drawableLeft or android:drawableRight or android:drawableTop or android:drawableBottom and android:drawablePaddig to achieve the same visual result in just one view.
for example:
<LinearLayout orientation=vertical>
<ImageView/>
<TextView/>
</LinearLayout>
is pretty much the same as
<Button
drawableLeft="#drawable/..."
text="..."
/>
that way your whole layout is simpler and the pressed states works out-of-the-box.
Consider using a single TextView and using the android:drawableLeft or android:drawableRight attribute to show your image. It's better design and more performant than a LinearLayout with two children.
If that won't work for you, try adding android:addStatesFromChildren="true" to the LinearLayout.
I've seen many of questions for how to add TextView in a RelativeLayout programatically, but everybody adding it in LinearLayout with orientation vertical. Can any one suggest me or give me a link that how to add multiple TextView in RelativeLayout at right until it has space and then change the line.
I want a layout like this..
May be this works for you !
You can customize chips-edittext-library for your need. Customizing by setting background to transparent, and editable to false.
-> Or you can use any other library which is used for displaying emoticon in EditText and customize it according to your need. Like android-emoticon-edittext-spike
You can use the Flow Layout library that manages the view arrangement itself.
When there is no space left the added View is moved to the next line
I have a LinearLayout which contains about 10 TextViews. I want the text of each TextView to be right justified. For now I have added android:gravity="right" for each of the TextViews, but I would like to have a better way out.
I would like to specify the alignment (or even style) of the all the children in the parent itself, so that all the children in the layout have the same style (instead of specifying the style separately for each children). Is that possible?
See the below article. You can declare styles in order to save yourself from headache
http://developer.android.com/guide/topics/ui/themes.html
Use a LinearLayout and specify: android:layout_gravity="right"
More info here: http://developer.android.com/reference/android/widget/LinearLayout.LayoutParams.html#attr_android:layout_gravity
I have a list view which has a footer.
It displays numbers and at the bottom is the total.
I want to be able to show the rows without a divider between them. OTOH I DO want a divider before the summary row.
Is there any easy way to do this?
You can set android:dividerHeight to 0 in your list.
Then use custom layout for footer in which you add divider by yourself. For example, that can be a TextView with no text, android:layout_height set to 2 and android:background set to some color.
When you have custom layout for the footer, just add divider on top of it. It can be for example View of hight 2dp and different background color.
I had to do this programatically, since setting android:dividerHeight="0dip" in the XML didn't work for me:
getListView().setDividerHeight(0);
I have an application to show the MapView having both height and width fill_parent. I need to overlay some text on the top part of the Map View. How to do this?. The background of text should be transparent. Also the text has the property of marquee. Is it possible to do this?
Use a RelativeLayout as the root container of you layout and add the MapView and a TextView to it (below the MapView in the layout xml file). Use the TextView to display the text which should be displayed above the map. Now you can use the attributes starting withlayout_ to place the TextView where you want it.
As far as I know, the marquee effect only works when the TextView is focused and its text value is too long to fit in the whole TextView.
The TextView's background should be transparent by default.
Create a RelativeLayout as the container of your Mapview and a TextView
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<MapView .../>
<TextView /> </RelativeLayout>
You can display the TextView where you want with the RelativeLayout child attributes, for example on the textView : layout_alignParentBottom="true"
Otherwise just use an itermized overlay to put the text in.