I have two Activities: Activity1 and Activity2 , both heirs of AbstractActivity .

AbstractActivity has a function that calls a popup with a button:

 <Button android:id="@+id/button_error_popup" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_marginBottom="@dimen/margin_small" android:minHeight="40dp" android:padding="@dimen/padding_default" android:textColor="@color/colorPrimaryDark" android:textSize="@dimen/text_size_default" /> 

The textcolor attribute works in both Activity. But. In Activity1 , the button has a gray background , and in Activity2 is black.

If you add an attribute, for example,

android:background="@android:color/holo_blue_bright"

Likewise, the background of the first button will change to blue, the background of the second button will remain black. Question: why is this happening and how to set the background of the second button?

styles.xml

 <style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar"> <!-- 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:fontFamily">@font/cuprum_regular</item> <item name="android:statusBarColor" tools:targetApi="lollipop">@color/colorAccent</item> </style> 

UPD1:

Understanding, I came to this intermediate conclusion: the background of the second button is the colorAccent from AppTheme . By changing it, the background of the second button also changed. Only this is clearly not a solution, to change one of the basic colors of the theme for the button.

It is clear that style is needed here. Tried to do so:

 <style name="buttonErrorPopupStyle" parent="Theme.MaterialComponents.Light.NoActionBar"> <item name="android:background">@android:color/holo_blue_bright</item> <item name="android:textColor">@android:color/holo_blue_bright</item> </style> 

Applying this to the button, the effect is similar: the text color changes, the background color does not.

Intuitively, I understand that my attribute is simply “not found” and, in the absence of it, they put the theme attribute instead. But why is this happening and how to solve it is still not clear.

UPD2

I figured out why the buttons had a different background in different Activity . For some reason, in the manifesto of the first Activity was a topic with its own attributes.

The actual question is why it does not work android:background

  • In the manifesto they use the same theme? - Andriy Martsinkevych
  • Yes. There are no topics at all. - KirstenLy

1 answer 1

I decided to replace the button with android.support.v7.widget.AppCompatButton