Android CalendarView Year Text Color - java

I'm styling the CalendarView in Android Studio and I already achieved to change the selected color
with the following code:
layout:
<CalendarView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/CalenderViewCustom"
android:dateTextAppearance="#style/CalenderViewDateCustomText"
android:weekDayTextAppearance="#style/CalenderViewWeekCustomText">
</CalendarView>
styles.xml:
<style name="CalenderViewCustom" parent="Theme.AppCompat">
<item name="colorAccent">#color/mainSelectedColor</item>
</style>
<style name="CalenderViewDateCustomText" parent="android:TextAppearance.DeviceDefault.Small">
<item name="android:textColor">#color/colorBlack</item>
</style>
<style name="CalenderViewWeekCustomText" parent="android:TextAppearance.DeviceDefault.Small">
<item name="android:textColor">#color/colorBlack</item>
</style>
The problem is that my result does not show the year and the month like you can see in the result:
I already tried to change the header attributes like headerMonthTextApperance but nothing seems to work for me.

Hi you cant use this library
https://github.com/SundeepK/CompactCalendarView
full performance and customizable
<com.github.sundeepk.compactcalendarview.CompactCalendarView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/compactcalendar_view"
android:layout_width="fill_parent"
android:paddingRight="10dp"
android:paddingLeft="10dp"
android:layout_height="250dp"
app:compactCalendarTargetHeight="250dp"
app:compactCalendarTextSize="12sp"
app:compactCalendarBackgroundColor="#ffe95451"
app:compactCalendarTextColor="#fff"
app:compactCalendarCurrentSelectedDayBackgroundColor="#E57373"
app:compactCalendarCurrentDayBackgroundColor="#B71C1C"
app:compactCalendarMultiEventIndicatorColor="#fff"
/>

Related

How to style android studio material slider

How can I style the slider, for example change colors for its track and thumb etc using xml?
slider.xml:
<com.google.android.material.slider.Slider
android:id="#+id/settingsMission_changeShakeDif_slider"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:stepSize="20.0"
android:theme="#style/SliderTheme"
android:valueFrom="0.0"
android:valueTo="40.0"
app:labelBehavior="gone" />
themes.xml
<style name="SliderTheme" parent="Widget.MaterialComponents.Slider">
<!-- Add attributes here -->
<item name="trackColorActive">#238ae6</item>
<item name="trackColorInactive">#a7bada</item>
<item name="tickColor">#13161d</item>
<item name="thumbColor">#238ae6</item>
</style>
When I do it like this, the color of my slider did not change (it remained the default purple color)
And when I try to run the app and open the bottom sheet dialog that has the slider, the app crashes. I am getting this runtime error too:
Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.AppCompat (or a descendant).
Found this useful article that solved my problem:
https://github.com/material-components/material-components-android/issues/1145
changes made to code:
slider.xml
<com.google.android.material.slider.Slider
android:id="#+id/settingsMission_changeShakeDif_slider"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:stepSize="20.0"
android:theme="#style/AppTheme"
android:valueFrom="0.0"
android:valueTo="40.0"
app:labelBehavior="gone"
app:thumbColor="#238ae6"
app:tickColor="#13161d"
app:trackColorActive="#238ae6"
app:trackColorInactive="#a7bada" />
themes.xml
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">

Style not applied when called

so Im new to android and this is my problem :
-when I call style to a textview it doesn't change anything ,here is my style.xml :
<?xml version="1.0" encoding="utf-8"?>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- App branding color for the app bar -->
<item name="colorPrimary">#009688</item>
<!-- Darker variant for the status bar and contextual app bars -->
<item name="colorPrimaryDark">#00796B</item>
<!-- Theme UI controls like checkboxes and text fields -->
<item name="colorAccent">#536DFE</item>
</style>
<!-- Style for header text in the order form -->
<style name="HeaderTextStyle">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">48dp</item>
<item name="android:gravity">center_vertical</item>
<item name="android:textAllCaps">true</item>
<item name="android:textSize">15sp</item>
<item name="android:textColor">#FF5252</item>
</style>
and here is how I call the style
<TextView
android:hint="#string/topping"
style="#style/HeaderTextStyle"
/>
I tried to change just the color of the textview using
android:textColor="#FF5252"
but it did nothing
could someone help me , Ill be so greatful ,
Thanks in advance
You are setting textColor while you havent set text yet, you need to change textColo to textColorHint or change hint to text if you want to use textColor, for hint you use textColorHint and for text you use textColor like this.
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="some text"
android:textColor="#color/colorPrimaryNero"
android:hint="some hint"
android:textColorHint="#color/colorPrimaryWhite" />

How can I add a background color to an Android SwitchPreference? [duplicate]

This question already has answers here:
Custom SwitchPreference in Android
(4 answers)
Closed 5 years ago.
I am using a PreferenceFragment to inflate an xml file with a single SwitchPreference. How can I make the background color of that preference including the title of the SwitchPreference to match the image below. I have tried setting the background but I am only able to set the background color of the switch icon.
styles.xml (make this style in style.xml file in values folder)
<resources>
<style name="SwitchTheme" parent="Theme.AppCompat.Light">
<!-- switch on thumb & track color -->
<item name="colorControlActivated">#02c754</item>
<!-- switch off thumb color -->
<item name="colorSwitchThumbNormal">#f1f1f1</item>
<!-- switch off track color -->
<item name="android:colorForeground">#42221f1f</item>
</style>
</resources>
your_layout_activity.xml
<android.support.v7.widget.SwitchCompat
android:id="#+id/switch_on_off"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_gravity="center"
android:checked="true"
android:gravity="center"
android:paddingLeft="30dp"
android:theme="#style/SwitchTheme"
app:switchMinWidth="55dp"/>
this source is worked for me. Try with this you will get understand
I have done this using the style
Style.xml
<style name="SwitchTheme" parent="Theme.AppCompat.Light">
<item name="colorControlActivated">#color/yourcolor</item>
</style>
in Layout
<android.support.v7.widget.SwitchCompat
android:id="#+id/switch_on_off"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_gravity="center"
android:checked="false"
android:gravity="center"
android:paddingLeft="#dimen/padding"
android:paddingRight="#dimen/padding"
app:switchMinWidth="#dimen/switch_size"
app:theme="#style/SwitchTheme" />

Toolbar Selected Tab Text Color Android

I am trying to set custom color for Tab text in one of my android application but instead change its setting white color for it. Other tab text is going changed but not changing only for selected Tab.
My Style for Tab is like below
<style name="MineCustomTabText"
parent="TextAppearance.Design.Tab">
<item name="tabSelectedTextColor">#000</item>
<item name="android:textColor">#color/TextColorLite</item>
<item name="android:textSize">#dimen/textPageCount</item>
</style>
I am using it in My Layout XML is like below
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
app:tabGravity="fill"
app:tabTextAppearance="#style/MineCustomTabText"
app:tabMode="fixed"
android:layout_height="wrap_content" />
You can see I have set black color for selected tab in style but its showing only white color. Let me know what I am missing. Thanks
Try this following code:
Add this style into your TabLayout
<android.support.design.widget.TabLayout
style="#style/MyCustomTabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
Add this style into your Style.xml
<style name="MyCustomTabLayout" parent="Widget.Design.TabLayout">
<!--<item name="tabMaxWidth">#dimen/tab_max_width</item>-->
<item name="tabIndicatorColor">#color/appcolor</item>
<item name="tabIndicatorHeight">2dp</item>
<item name="tabPaddingStart">10dp</item>
<item name="tabPaddingEnd">10dp</item>
<item name="tabBackground">#color/lightblue</item>
<item name="tabTextAppearance">#style/MyCustomTabTextAppearance</item>
<item name="tabSelectedTextColor">#color/appcolor</item>
</style>
<style name="MyCustomTabTextAppearance" parent="TextAppearance.Design.Tab">
<item name="android:textSize">15sp</item>
<item name="android:textColor">#color/black</item>
<item name="textAllCaps">true</item>
</style>
Another way to change programmatically:
tabLayout.setSelectedTabIndicatorColor(Color.parseColor("#FF0000"));
tabLayout.setSelectedTabIndicatorHeight((int) (5 * getResources().getDisplayMetrics().density));
tabLayout.setTabTextColors(Color.parseColor("#727272"), Color.parseColor("#ffffff"));
I hope this will help you
Add tab_text_color.xml in drawable folder like below
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_selected="true"
android:color="#color/text_tab_selected" />
<item
android:state_selected="false"
android:color="#color/text_tab_unselected" />
</selector>
then in style.xml do this and check
<style name="CustomTabPageIndicator.Text" parent="android:TextAppearance.Medium">
<item name="android:textColor">#drawable/tab_text_color</item>
...
</style>

issue in custom title bar (android)

when i customize title bar in view by adding a image, i face an issue as the images is not fixed to the edges accurately. I have attached the image where you can see space between the window margin and image added. How to overcome this problem. Below are the code that i have used to customize the title bar. Can anyone help me to fix this issue.
java code :
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.home_view);
this.getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
R.layout.upwindow);
layout code :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="32dp">
<ImageView
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/up_bar"
android:src="#drawable/up_bar" />
<TextView
android:id="#+id/pagename"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="Sify MyStorage"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
create style xml in values folder :
<resources>
<style name="CustomWindowTitleBackground" />
<style name="CustomTheme" parent="android:Theme">
<item name="android:windowTitleSize">32dp</item>
<item name="android:windowTitleBackgroundStyle">#style/CustomWindowTitleBackground
</item>
</style>
</resources>
then refer it in manifest as :
android:theme="#style/CustomTheme">
this will solve it .
hope this help .
Do you have different images for different resolutions? It might be that your image simply does not fit that space, and that you need a larger one. Be careful though, you might run into issues with your app working across different platforms with scaling.
You need to play a little with styling in order to override this behavior. Define a custom theme (style) as below:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="customTitle">
<item name="android:background">#drawable/up_bar</item>
</style>
<style name="myTheme" parent="android:Theme">
<item name="android:windowTitleBackgroundStyle">#style/customTitle</item>
</style>
</resources>
and then use this theme in your activity by applying android:theme="#style/myTheme" to your desired activity tag in AndroidManifest.xml
requestWindowFeature(Window.FEATURE_NO_TITLE);
and setBackground to your layout in layout file...
Like,,,
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent" android:background="#drawable/up_bar" <---Add this
android:layout_height="32dp">
and Remove imageview from xml

Categories