Overriding Referenced Style Attributes

Overriding referenced style attributes

I think you need that line in your theme

<item name="android:checkedTextViewStyle">@style/ListViewCheckedTextViewRowStyle</item>

so it would look like this:

<style name="Theme.Yellowgreen" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:listChoiceIndicatorMultiple">@drawable/btn_check_holo_light</item>
<item name="android:checkedTextViewStyle">@style/ListViewCheckedTextViewRowStyle</item>
</style>

UPDATE

After question update and some additional information form comments we found that the problem was in Context. It's the same mistake I did in that my question: Android color selector doesn't work with custom attributes

To one fragment was passed Activity and to the other Application. I'm not an expert but even both of those classes are extending Context only the Activity extends ContextThemeWrapper, which has information about styles. It might be helpful to read that article for future understanding Context: http://www.doubleencore.com/2013/06/context/

How to override attributes of a style in a android view

It doesn't look to me like insetLeft is part of the style you reference Widget.MaterialComponents.Button.TextButton. Let's ascend the hierarchy by entering Ctrl-B on each style reference.

This is the style definition i material-1.4.0 values.xml:

</style>
<style name="Widget.MaterialComponents.Button.TextButton" parent="Widget.MaterialComponents.Button.UnelevatedButton">
<item name="android:textColor">@color/mtrl_text_btn_text_color_selector</item>
<item name="android:paddingLeft">@dimen/mtrl_btn_text_btn_padding_left</item>
<item name="android:paddingRight">@dimen/mtrl_btn_text_btn_padding_right</item>
<item name="iconTint">@color/mtrl_text_btn_text_color_selector</item>
<item name="iconPadding">@dimen/mtrl_btn_text_btn_icon_padding</item>
<item name="backgroundTint">@color/mtrl_btn_text_btn_bg_color_selector</item>
<item name="rippleColor">@color/mtrl_btn_text_btn_ripple_color</item>
</style>

Now, let's look at "Widget.MaterialComponents.Button.UnelevatedButton":

<style name="Widget.MaterialComponents.Button.UnelevatedButton">
<item name="android:stateListAnimator" ns1:ignore="NewApi">@animator/mtrl_btn_unelevated_state_list_anim</item>
<item name="elevation">0dp</item>
</style>

The hierarchy ends there. I don't see the insetLeft attribute referenced anywhere, so you can't be overriding it in your layout - a least through the style reference in your layout.

Specify what you are trying to do for an answer that might help.

Overriding a custom attribute in a flavor by referring to another style

I found a solution to my problem!
The solution is to use inheritance rather referring to another style.

<style name="CardStyle" parent="CardView">
<item name="cardCornerRadius">8dp</item>
<item name="cardElevation">6dp</item>
<item name="android:layout_marginEnd">16dp</item>
<item name="android:layout_marginStart">16dp</item>
<item name="android:layout_marginTop">10dp</item>
<item name="android:layout_marginBottom">10dp</item>
</style>

<style name="SettingsCardStyle" parent="CardStyle">

How to override (or hide) style attributes defined in the Android library project?

To disable android:layout_toRightOf, you can set it to @null. If your app defines the ListItemText style as follows, it should work as you want:

<style name="ListItemText">
<item name="android:layout_toRightOf">@null</item>
<item name="android:layout_below">@id/preview_image</item>
</style>

Override property in style= attribute?

The only way to override the properties specified in a style attribute is to use !important.

Overriding items in Android's style.

Since no one picked the glove eventually I found the solution, indeed as an attribute.

The solution:

  1. In your attrs.xml create an entry for the value you need, for drawbale like selector for example use: <attr name="ListResultSelector" format="reference" />

  2. In your theme.xml define your theme, if that attribute is your only one and you want Android normal theme as your theme you can use:

    <style name="Theme" parent="@android:style/Theme.NoTitleBar">
    <item name="ListResultSelector">@android:drawable/list_selector_background</item>
    </style>
  3. If you want to override in a specific application you can simple inherit 'theme' (<style name="Theme.newTheme">) and change that specific property there.

  4. In your style instead of defining a drawable you can define: <....android:background="?attrib:ListResultSelector" ../>

  5. Apply the theme either to your application or to the relevant activity

In this way I don't need to override an entire style, only special properties like drawables, type faces etc... inside it. So if I ever need to change something in the original style and I want it to effect both the old and the new applications I don't need to do it twice.

How do you determine what is overriding your style?

In devtools, in the style inspector, choose Computed. Find the property you are interested in and click it. You will see a list of all the rules that apply to this property, with the active one at the top, and each with a file/line reference to where it is defined.

Consider the following HTML:

<style>
#foo { color: red; }
p { color: blue; }
</style>

<p id="foo">What color am I?</p>

You would see the following:

Sample Image

WPF Override Style Value

You're right, this method should work. Something else is setting the border's padding.

Snoop is telling you the padding is defined by the parent template, which could be the HeaderSite (ToggleButton).
You could try to extend the ToggleButton style (BasedOn) or redefine it locally.

How can I override inline styles with external CSS?

The only way to override inline style is by using !important keyword beside the CSS rule. The following is an example of it.

div {
color: blue !important;
/* Adding !important will give this rule more precedence over inline style */
}
<div style="font-size: 18px; color: red;">
Hello, World. How can I change this to blue?
</div>


Related Topics



Leave a reply



Submit