Android: AppCompatTextView custom style - java

I'm going to set default style for AppCompatTextView through whole application including android:textColor, android:maxLines, and android:inputType.
I found that I can set default style for AppCompatEditText by following codes.
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!--EditText Style-->
<item name="editTextStyle">#style/My_EditTextStyle</item>
</style>
<style name="My_EditTextStyle" parent="Widget.AppCompat.EditText">
<item name="android:maxLines">1</item>
<item name="android:inputType">text</item>
...
</style>
So what would be the item name for AppCompatTextView like "editTextStyle" here? I tried with "textViewStyle" but it doesn't work.

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:editTextStyle">#style/My_EditTextStyle</item>
<item name="editTextStyle">#style/My_EditTextStyle</item>
<item name="android:textViewStyle">#style/My_TextViewStyle</item>
<item name="textViewStyle">#style/My_TextViewStyle</item>
</style>
<style name="My_EditTextStyle" parent="#android:style/Widget.EditText">
<item name="android:maxLines">1</item>
<item name="android:inputType">text</item>
...
</style>
<style name="My_TextViewStyle" parent="#android:style/Widget.TextView">
<item name="android:maxLines">1</item>
<item name="android:inputType">text</item>
...
</style>

Replace your <style name="My_EditTextStyle" parent="#android:style/Widget.EditText">
With <style name="My_textView" parent="#android:style/Widget.TextView">
REFERENCE IT.

Related

How to change MaterialAlertDialog theme

Here is a dialog, how to change this color (unchecked)?
I try to set style but not work:
<style name="ThemeMyAppDialogAlertDay"
parent="ThemeOverlay.MaterialComponents.MaterialAlertDialog">
<item name="colorPrimary">#color/color_secondary</item>
<item name="colorPrimaryVariant">#color/color_primary_variant</item>
<item name="colorOnPrimary">#color/color_secondary</item>
<item name="colorSecondary">#color/color_secondary</item>
<item name="colorAccent">#color/color_error</item>
</style>
You can use:
<style name="ThemeMyAppDialogAlertDay"
parent="ThemeOverlay.MaterialComponents.MaterialAlertDialog">
<item name="colorSecondary">#color/selected</item> <!-- selected -->
<item name="colorControlNormal">#color/unselected</item> <!-- unselected -->
</style>
Try this , It should help
<style name="materialDiaog" parent="MaterialAlertDialog.MaterialComponents">
<item name="buttonTint">#color/colorPrimary</item>
<item name="colorPrimary">#color/color_secondary</item>
<item name="colorPrimaryVariant">#color/color_primary_variant</item>
<item name="colorOnPrimary">#color/color_secondary</item>
<item name="colorSecondary">#color/color_secondary</item>
<item name="colorAccent">#color/color_error</item>
</style>
<style name="AppTheme" parent="{set your parent theme here}">
<item name="materialAlertDialogTheme">#style/materialDiaog</item>
</style>

How to change Actionbar text color using Material Design?

I am using Material Design in my Android app and I want to change Actionbar text color and back button color.
This code is not working:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:windowContentOverlay">#null</item>
<!--<item name="android:textSize">3sp</item>-->
<item name="android:actionBarStyle">#style/MyTheme.ActionBarStyle</item>
</style>
<style name="MyTheme.ActionBarStyle" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:titleTextStyle">#style/MyTheme.ActionBar.TitleTextStyle</item>
</style>
<style name="MyTheme.ActionBar.TitleTextStyle" parent="#android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#color/titleColor</item>
</style>
Using the ActionBar in your theme you can use:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
<item name="actionBarTheme">#style/ThemeOverlay.Actionbar</item>
</style>
<style name="ThemeOverlay.Actionbar" parent="ThemeOverlay.MaterialComponents.Dark.ActionBar" >
<item name="android:textColorPrimary">#color/....</item>
</style>

How to change the color of an dialog item from black to white?

I'm using the following theme for my dialog:
<style name="AlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:textColorSecondary">#color/colorWhite</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:background">#color/colorPrimary</item>
<item name="android:textColor">#color/colorWhite</item>
<item name="android:textColorAlertDialogListItem">#color/colorWhite</item>
</style>
Everything works but the item text color. I need to be white, but for some reason, it remains back. How can I change that text to be white? Thanks
Edit:
Here is my AppTheme:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:textColorSecondary">#color/colorWhite</item>
</style>
You may refer AlertDialog Theme: How to change item text color?
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
...
<item name="textColorAlertDialogListItem">#color/colorWhite</item>
</style>
or
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
...
<item name="alertDialogTheme">#style/AlertDialogStyle </item>
</style>
<style name="AlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
...
<item name="textColorAlertDialogListItem">#color/colorWhite</item>
<!--
<item name="android:textColor">#color/colorWhite</item>
-->
</style>
Also you can change android:textColor, but it will change all the text color in Dialog Window
Use your custom DialogBox Style while creating DialogBox.
new AlertDialog.Builder(new ContextThemeWrapper(context, R.style.AlertDialogStyle))
Add these lines into your app theme
<item name="android:alertDialogTheme">#style/AlertDialogStyle</item>
<item name="android:alertDialogStyle">#style/AlertDialogStyle</item>

Android: ActionBar will not change its style?

I'm following the Android Documentation and have correctly copied this code:
<resources>
<style name="CustomTheme"
parent="Base.Theme.AppCompat.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:actionMenuTextColor">#color/actionbar_text</item>
</style>
<style name="MyActionBar"
parent="#android:style/Widget.Holo.ActionBar">
<item name="android:background">#color/background</item>
<item name="android:titleTextStyle">#style/MyActionBarTitleText</item>
</style>
<style name="MyActionBarTitleText"
parent="#android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#color/actionbar_text</item>
</style>
</resources>
I've set the activities manifest to "CustomTheme" and have the right information in strings.xml so I don't see what the problem would be. Any help would be appreciated. Thanks.
Try removing the android: tag and also, you have to set the Parent ActionBar to AppCompat's ActionBar.
<style name="CustomTheme"
parent="Base.Theme.AppCompat.Light">
<item name="actionBarStyle">#style/MyActionBar</item>
<item name="actionMenuTextColor">#color/actionbar_text</item>
</style>
<style name="MyActionBar"
parent="Base.Widget.AppCompat.ActionBar">
<item name="background">#color/background</item>
<item name="titleTextStyle">#style/MyActionBarTitleText</item>
</style>
<style name="MyActionBarTitleText"
parent="TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/actionbar_text</item>
</style>

Option Menu show incorrectly on Custom Style map

Option Menu show incorrectly on Custom Style map
The problem raised on an application in android
I have a custom theme on my app. The problem is that the option menu shows incorrectly ,so the option menu shows cut of on the screen.
I wondering why could happen?
This is my style file xml
<style name="AppTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:typeface">normal</item>
<item name="android:typeface">sans</item>
<item name="android:typeface">serif</item>
<item name="android:typeface">monospace</item>
<item name="android:actionBarItemBackground">#drawable/selectable_background_example</item>
<item name="android:popupMenuStyle">#style/PopupMenu.Example</item>
<item name="android:dropDownListViewStyle">#style/DropDownListView.Example</item>
<item name="android:actionBarTabStyle">#style/ActionBarTabStyle.Example</item>
<item name="android:actionDropDownStyle">#style/DropDownNav.Example</item>
<item name="android:actionBarStyle">#style/ActionBar.Solid.Example</item>
<item name="android:actionModeBackground">#drawable/cab_background_top_example</item>
<item name="android:actionModeSplitBackground">#drawable/cab_background_bottom_example</item>
<item name="android:actionModeCloseButtonStyle">#style/ActionButton.CloseMode.Example</item>
</style>
<style name="ActionBar.Solid.Example" parent="#android:style/Widget.Holo.Light.ActionBar.Solid">
<item name="android:background">#drawable/ab_solid_example</item>
<item name="android:backgroundStacked">#drawable/ab_stacked_solid_example</item>
<item name="android:backgroundSplit">#drawable/ab_bottom_solid_example</item>
<item name="android:progressBarStyle">#style/ProgressBar.Example</item>
</style>
<style name="ActionBar.Transparent.Example" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#drawable/ab_transparent_example</item>
<item name="android:progressBarStyle">#style/ProgressBar.Example</item>
</style>
<style name="PopupMenu.Example" parent="#android:style/Widget.Holo.Light.ListPopupWindow">
<item name="android:popupBackground">#drawable/menu_dropdown_panel_example</item>
</style>
<style name="DropDownListView.Example" parent="#android:style/Widget.Holo.Light.ListView.DropDown">
<item name="android:listSelector">#drawable/selectable_background_example</item>
</style>
<style name="ActionBarTabStyle.Example" parent="#android:style/Widget.Holo.Light.ActionBar.TabView">
<item name="android:background">#drawable/tab_indicator_ab_example</item>
</style>
<style name="DropDownNav.Example" parent="#android:style/Widget.Holo.Light.Spinner">
<item name="android:background">#drawable/spinner_background_ab_example</item>
<item name="android:popupBackground">#drawable/menu_dropdown_panel_example</item>
<item name="android:dropDownSelector">#drawable/selectable_background_example</item>
</style>
<style name="ProgressBar.Example" parent="#android:style/Widget.Holo.Light.ProgressBar.Horizontal">
<item name="android:progressDrawable">#drawable/progress_horizontal_example</item>
</style>
<style name="ActionButton.CloseMode.Example" parent="#android:style/Widget.Holo.Light.ActionButton.CloseMode">
<item name="android:background">#drawable/btn_cab_done_example</item>
</style>
<!-- this style is only referenced in a Light.DarkActionBar based theme -->
<style name="Theme.Example.Widget" parent="#android:style/Theme.Holo">
<item name="android:popupMenuStyle">#style/PopupMenu.Example</item>
<item name="android:dropDownListViewStyle">#style/DropDownListView.Example</item>
</style>
For any ones that have this same trouble, the solution , in my case , was solved by added this line in the manifest file.
<supports-screens
android:anyDensity="true" />

Categories