In my app i don't know how the color of activity label changed from white to black. I want to to make it white again. I tried various ways. Here are some pieces of code:
This is my action bar:
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/appBar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolBar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:popupTheme="#style/Theme.FlikrApp"/>
</com.google.android.material.appbar.AppBarLayout>
This is my theme:
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.FlikrApp" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">#color/primary</item>
<item name="colorPrimaryVariant">#color/primary_dark</item>
<item name="colorOnPrimary">#color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">#color/accent</item>
<item name="colorSecondaryVariant">#color/accent</item>
<item name="colorOnSecondary">#color/icons</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
<item name="android:windowBackground">#color/primary_light</item>
<item name="icon">#color/icons</item>
<item name="android:textColorSecondary">#color/white</item>
<item name="android:navigationBarColor">#color/primary_dark</item>
</style>
<style name="Theme.FlikrApp.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="Theme.FlikrApp.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="Theme.FlikrApp.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>
I tried this as well in onCreate method but didn't work:
getSupportActionBar().setTitle(Html.fromHtml("<font-color\"white\">Flikr App</font>"));
I added to my themes this as well but nothing
<style name="TextAppearance.AppCompat.Widget.ActionBar.Title" parent="TextAppearance.AppCompat.Title">
<item name="android:textColor">#color/white</item>
</style>
Also tried changing theme and popupTheme of my tool bar but if it worked i won't be writting this.
Use material design theme which automatically colors the statusBar as colorPrimaryDark value. Change your colorDarkPrimary according to the color of status bar you want.
<?xml version="1.0"?>
-<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
-<style parent="Theme.MaterialComponents.DayNight.DarkActionBar" name="Theme.StairwaysToSolutions">
<!-- Primary brand color. -->
<item name="colorPrimary">#color/purple_500</item>
<item name="colorPrimaryVariant">#color/purple_700</item>
<item name="colorOnPrimary">#color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">#color/teal_200</item>
<item name="colorSecondaryVariant">#color/teal_700</item>
<item name="colorOnSecondary">#color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
</resources>
Save this file as themes.xml, and then in Manifest replace theme with this.
<application android:theme="#style/Theme.StairwaysToSolutions" android:supportsRtl="true" android:roundIcon="#mipmap/ic_launcher_round" android:label="#string/app_name" android:icon="#mipmap/ic_launcher" android:allowBackup="true">
Nothing worked for me till now but then I came up with a way that has to do nothing with theme.xml file.
I added this to my onCreate
actionBar.setDisplayShowTitleEnabled(false);
And then added a custom TextView in my ToolBar`:
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/appBar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolBar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:popupTheme="#style/Theme.FlikrApp">
<TextView
android:id="#+id/custom_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/app_name"
android:textColor="#color/white"
android:textSize="20sp"
android:fontFamily="sans-serif-medium"/>
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
I literally tried everything possible to do this and I guess it was probably the last thing left to do and gladly it worked!
Related
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" />
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>
I am trying to create a custom rating bar where number of stars is dynamic and the drawable that I need to use also depends on the type, that I get from server.
I am doing this -
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:id="#+id/rating_bar_star"
android:layout_gravity="center"
style="#style/RatingBarStar"
android:stepSize="0.1"/>
then I added this in style -
<style name="RatingBarStar" parent="#android:style/Widget.RatingBar">
<item name="android:progressDrawable">#drawable/rating_bar</item>
<item name="android:minHeight">20dip</item>
<item name="android:maxHeight">20dip</item>
</style>
this is my rating_bar.xml I added in drawable -
<?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/rating_bar_empty" />
<item android:id="#android:id/secondaryProgress"
android:drawable="#drawable/rating_bar_empty" />
<item android:id="#android:id/progress"
android:drawable="#drawable/rating_bar_filled" />
</layer-list>
rating_bar_empty.xml
<item android:state_pressed="true"
android:state_window_focused="true"
android:drawable="#drawable/rating_off" />
<item android:state_focused="true"
android:state_window_focused="true"
android:drawable="#drawable/rating_off" />
<item android:state_selected="true"
android:state_window_focused="true"
android:drawable="#drawable/rating_off" />
<item android:drawable="#drawable/rating_off" />
and rating_bar_filled.xml -
<item android:state_pressed="true"
android:state_window_focused="true"
android:drawable="#drawable/rating_on" />
<item android:state_focused="true"
android:state_window_focused="true"
android:drawable="#drawable/rating_on" />
<item android:state_selected="true"
android:state_window_focused="true"
android:drawable="#drawable/rating_on" />
<item android:drawable="#drawable/rating_on" />
and then added this in my java file -
rating_bar_star.setNumStars(getStars());
Obviously I am getting stars from server. Now my problem is when I click/select a star it doesn't select one whole star.
If number of star is 6 and I set stepSize as 0.8 then it works fine but same stepSize doesn't work for 10 stars. All I want, my stars to show selected appearance for selected stars.
this is what I get when I don't set stepSize and select/click on first star
and this when I click on second -
I need to store the current style of button,so that whenever activity is sent to background or destroyed and restarted the buttons retain the style they had last time.I know how to save and retrieve information for textviews but i have no idea how to do that for button styles, basically i am more confused about how to retrieve it.
Here is my code for setting button style:
case R.id.darkorange:
for (Button currentButton : buttons) {
currentButton.setBackgroundResource(R.drawable.darkorange);
}
Now orange can be anything purple, red, blue or green. How do i save this inforation about button and retrive it later when activity is recreated.
Do it like these:
res/drawable/solid.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient
android:startColor="#0078a5"
android:endColor="#00adee"
android:angle="90"/>
<padding android:left="15dp"
android:top="1dp"
android:right="15dp"
android:bottom="1dp" />
<stroke
android:width="1dp"
android:color="#0076a3" />
<corners android:radius="8dp" />
</shape>
activity_main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="#+id/button1"
style="#style/NiceButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Colors"/>
</LinearLayout>
res/values/strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Buttons</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Color</string>
</resources>
res/values/styles.xml:
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<style name="NiceButton" parent="#android:style/Widget.Button">
<item name="android:gravity">center_vertical|center_horizontal</item>
<item name="android:textColor">#FFFFFF</item>
<item name="android:background">#drawable/solid</item>
<item name="android:textSize">16sp</item>
<item name="android:textStyle">bold</item>
<item name="android:focusable">true</item>
<item name="android:clickable">true</item>
</style>
</resources>
Output:
Does anyone know what is the location of Holo theme focused button drawable? I would like to set it to my View on some event, but I can't find it.
1.first locate following location in your android sdk platforms folder -
yourandroidsdkrootfolderpath\platforms\android-11\data\res\drawable
(ex:D:\android\platforms\android-11\data\res\drawable)
2.find the xml file on folder named as btn_default_holo_dark.xml
and it's contain like below code:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false" android:state_enabled="true"
android:drawable="#drawable/btn_default_normal_holo_dark" />
<item android:state_window_focused="false" android:state_enabled="false"
android:drawable="#drawable/btn_default_normal_disable_holo_dark" />
<item android:state_pressed="true"
android:drawable="#drawable/btn_default_pressed_holo_dark" />
<item android:state_focused="true" android:state_enabled="true"
android:drawable="#drawable/btn_default_selected_holo_dark" />
<item android:state_enabled="true"
android:drawable="#drawable/btn_default_normal_holo_dark" />
<item android:state_focused="true"
android:drawable="#drawable/btn_default_normal_disable_focused_holo_dark" />
<item
android:drawable="#drawable/btn_default_normal_disable_holo_dark" />
</selector>
3.copy xml to your project drawable folder
4.copy drawable-hdpi,drawable-ldpi,drawable-mdpi images mentioned above xml like
btn_default_normal,btn_default_normal_disable,btn_default_pressed,btn_default_selected,btn_default_normal,btn_default_normal_disable_focused,btn_default_normal_disable
5.add style to your style.xml file like below
<style name="Custombutton" parent="Widget.Button">
<item name="android:background">#android:drawable/btn_default_holo_dark</item>
<item name="android:textAppearance">?android:attr/textAppearanceMedium</item>
<item name="android:textColor">#android:color/primary_text_holo_dark</item>
<item name="android:minHeight">48dip</item>
<item name="android:minWidth">64dip</item>
</style>
6.apply your button style like below code:
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
style="#style/Custombutton"
android:layout_height="wrap_content"
android:text="Button" />
Hdpi versions:
/<android sdk path>/platforms/android-15/data/res/drawable-hdpi/btn_default_disabled_holo.9.png
/<android sdk path>/platforms/android-15/data/res/drawable-hdpi/btn_default_focused_holo.9.png
/<android sdk path>/platforms/android-15/data/res/drawable-hdpi/btn_default_normal_holo.9.png
/<android sdk path>/platforms/android-15/data/res/drawable-hdpi/btn_default_pressed_holo.9.png
other resolutions are in drawable-ldpi,drawable-mdpi,drawable-xhdpi directories.