I'm trying to change the fontFamily of a CalendarView in xml, but it's not happening. Below is the code :
CalendarView :
<CalendarView
android:id="#+id/calendar_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:dateTextAppearance="#style/CalendarViewTheme"
/>
styles.xml :
<style name="CalendarViewTheme" parent="#android:style/TextAppearance.Small">
<item name="android:textSize">14.5sp</item>
<item name="android:textColor">#color/calendar_text_color</item>
<item name="android:fontFamily">#font/sf_pro_semi_bold</item>
</style>
calendar_text_color.xml :
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#color/colorWhite" android:state_selected="true" />
<item android:color="#color/colorWhite" android:state_focused="true" />
<item android:color="#color/colorWhite" android:state_pressed="true" />
<item android:color="#color/colorWhite" android:state_activated="true" />
<item android:color="#color/colorHints" android:state_enabled="false" />
<item android:color="#color/colorBlack" />
</selector>
Related
Hello I have a rating bar with custom drawable but it only displays full stars only and not showing half
here is my code, how can I solve this?
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#android:id/background"
android:drawable="#drawable/empty_star" />
<item
android:id="#+id/secondaryProgress"
android:drawable="#drawable/empty_star" />
<item
android:id="#android:id/progress"
android:drawable="#drawable/filled_star" />
<style name="doctor_rating" parent="#style/Widget.AppCompat.RatingBar">
<item name="android:minHeight">13dp</item>
<item name="android:minWidth">65dp</item>
<item name="android:numStars">5</item>
<item name="android:progressDrawable">#drawable/custom_rating_stars</item>
<item name="android:stepSize">.1</item>
</style>
<RatingBar
android:id="#+id/doctor_rating_bar"
style="#style/doctor_rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_gravity="end"
android:rating="3.5"
/>
See below code this will help you.
custom_rating_stars.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#android:id/background"
android:drawable="#drawable/ratingbar_empty" />
<item
android:id="#android:id/progress"
android:drawable="#drawable/ratingbar_filled" />
</layer-list>
ratingbar_empty.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:state_window_focused="true"
android:drawable="#drawable/star_grey_small" />
<item android:state_focused="true"
android:state_window_focused="true"
android:drawable="#drawable/star_grey_small" />
<item android:state_selected="true"
android:state_window_focused="true"
android:drawable="#drawable/star_grey_small" />
<item android:drawable="#drawable/star_grey_small" />
</selector>
ratingbar_filled.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:state_window_focused="true"
android:drawable="#drawable/star_yellow" />
<item android:state_focused="true"
android:state_window_focused="true"
android:drawable="#drawable/star_yellow" />
<item android:state_selected="true"
android:state_window_focused="true"
android:drawable="#drawable/star_yellow" />
<item android:drawable="#drawable/star_yellow" />
</selector>
Try this:
<style name="doctor_rating" parent="android.widget.RatingBar">
<item name="android:minHeight">13dp</item>
<item name="android:minWidth">65dp</item>
<item name="android:numStars">5</item>
<item name="android:progressDrawable">#drawable/custom_rating_stars</item>
<item name="android:stepSize">0.1</item>
I have this view called ButtonMultiline:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:gravity="center">
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/ButtonMultilineCatalogTitle"
android:text="title"/>
<TextView
android:id="#+id/subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/ButtonMultilineCatalogSubtitle"
android:text="subtitle"/>
I apply a background on this layout to change color on press:
<selector android:exitFadeDuration="200"
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:drawable="#drawable/btn_large_normal" />
<item android:state_pressed="true">
<color android:color="#color/background_black_top" />
</item>
<item android:state_focused="true" android:drawable="#drawable/btn_large_pressed" />
<item android:drawable="#drawable/btn_large_pressed" android:state_hovered="true" />
<item android:state_checked="true" android:drawable="#drawable/btn_large_normal" />
<item android:drawable="#drawable/btn_large_normal" />
All works fine until here.
I want to change the both TextView color on press too, but when I add this line in both TextView, there is a crash on inflate problem on this button_text_catalog.xml:
<android:background="#drawable/button_text_catalog">
My button_text_catalog.xml:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#color/white" android:state_pressed="true" />
<item android:color="#color/white" android:state_focused="true" />
<item android:color="#color/theme_primary"/>
Thanks guys!
Use this code:
button_text_catalog.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- pressed -->
<item android:state_pressed="true" android:color="#color/white"/>
<!-- focused -->
<item android:state_focused="true" android:color="#color/white"/>
<!-- activated -->
<item android:state_activated="true" android:color="#color/white"/>
<!-- checked -->
<item android:state_checked="true" android:color="#color/white"/>
<!-- default -->
<item android:color="#color/theme_primary"/>
</selector>
in Style.xml
add <item name="android:textColor">#drawable/button_text_catalog</item>
I have the following Button style:
<style name="ButtonmyTimeRed" parent="android:Widget.Button">
<item name="android:minHeight">48dip</item>
<item name="android:minWidth">64dip</item>
<item name="android:textColor">#ffffff</item>
<item name="android:background">#drawable/button_selector_red</item>
</style>
<style name="ImageButtonmyTimeRed" parent="android:Widget.ImageButton">
<item name="android:background">#drawable/button_selector_red</item>
</style>
with the following selector:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!--<item android:state_window_focused="false" android:state_enabled="true" android:drawable="#drawable/button_shape_red" />-->
<!--<item android:state_window_focused="false" android:state_enabled="false" android:drawable="#drawable/button_shape_disabled" />-->
<!--<item android:state_focused="true" android:state_enabled="true" android:drawable="#drawable/button_shape_red" />-->
<item android:drawable="#drawable/button_shape_red_pressed" android:state_pressed="true"/>
<item android:drawable="#drawable/button_shape_red" android:state_focused="true"/>
<item android:drawable="#drawable/button_shape_disabled" android:state_enabled="false" />
<!--<item android:drawable="#drawable/button_shape_red" android:state_enabled="true" />-->
<item android:drawable="#drawable/button_shape_red"/>
</selector>
My shape looks like:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#color/red" />
</shape>
Everything works fine on Api level 14 and above. I don't have custom values-xx folders, so I'm wondering why my button has no background on the API 10 device.
My base theme is:
Theme.AppCompat.Light
and I'm using:
compile 'com.android.support:appcompat-v7:22.0.0'
The strange thing is that my ImageButton has the correct background.
UPDATE:
Seems "solid" does not work on onlder devices. When I put:
<stroke
android:width="3dp"
android:color="#color/red" />
<solid android:color="#color/red" />
I get a red border but no background
I am using a background 9 patch image name button_normal.9.png. The image is not showing as a background image of button. Got stuck for 5 hours still couldn't find it. Please help. Here are the respective files.
This is button:
<Button
android:id="#+id/s_id"
android:text="#string/s_id_string"
android:layout_marginTop="20dp"
style="#style/MainScreen"/>
Style MainScreen:
<style name="MainScreen">
<item name="android:layout_width">200dp</item>
<item name="android:layout_marginTop">10dp</item>
<item name="android:textSize">15dp</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textStyle">bold</item>
<item name="android:background">#drawable/button_shape</item>
<item name="android:textColor">#drawable/button_text_color</item>
</style>
button_shape file:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="#drawable/button_shape_normal"
android:background="#drawable/button_normal"
android:state_pressed="false"/>
<item
android:drawable="#drawable/button_shape_pressed"
android:state_pressed="true"
android:background="#ed2020"
/>
button_text_color file:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false" android:color="#ed2020"/>
<item android:state_pressed="true" android:color="#ffffff"/>
button_shape_pressed & button_shape_normal file is same:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="30dp" />
try this button_shape file:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="#drawable/button_shape_pressed"
android:state_pressed="true"
android:background="#ed2020" />
<item
android:drawable="#drawable/button_shape_normal"
android:background="#drawable/button_normal" />
</selector>
I was able to style button to my liking with pure XML (no image). Here is how it looks:
shape_button_normal_blue.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners android:radius="7dip"/>
<gradient android:startColor="#color/blue_start" android:endColor="#color/blue_end" android:angle="270" />
<stroke android:width="1dip" android:color="#80036990" />
<padding android:left="5dip" android:right="5dip" android:top="7dip" android:bottom="7dip"/>
</shape>
Similar to that I described other shapes for pressed/disabled/etc
Here is my selector_button_blue:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false" android:state_enabled="true"
android:drawable="#drawable/shape_button_normal_blue" />
<item android:state_window_focused="false" android:state_enabled="false"
android:drawable="#drawable/shape_button_disabled" />
<item android:state_pressed="true"
android:drawable="#drawable/shape_button_selected" />
<item android:state_focused="true" android:state_enabled="true"
android:drawable="#drawable/shape_button_focused_blue" />
<item android:state_enabled="true"
android:drawable="#drawable/shape_button_normal_blue" />
<item android:state_focused="true"
android:drawable="#drawable/shape_button_normal_blue" />
<item android:drawable="#drawable/shape_button_disabled" />
</selector>
And finally my style:
<style name="MyBlueButton" parent="#android:style/Widget.Button">
<item name="android:background">#drawable/selector_button_blue</item>
<item name="android:layout_marginLeft">1dp</item>
<item name="android:layout_marginRight">1dp</item>
<item name="android:layout_marginTop">5dp</item>
<item name="android:layout_marginBottom">5dp</item>
<item name="android:textColor">#color/white</item>
<item name="android:textSize">18dp</item>
<item name="android:textStyle">bold</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_width">fill_parent</item>
</style>
I'm using those buttons just fine with text. Happy and proud :)
Now I need to put icon on them. I see there is drawingTop/Bottom/Left/Right but it doesn't do what I need. What do I miss here? How do I make it nice and centered?
<Button style="#style/MyBlueButton" android:layout_marginTop="0dp" android:text="" android:layout_width="0dp" android:layout_weight="0.15"
android:drawableTop="#drawable/ic_accept"/>
use imagebutton, something like Edited
>
<ImageButton
android:id="#+id/call"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_accept"
android:background="#drawable/selector_button_blue"
/>