Android 相似的形状画得不同

Android 相似的形状画得不同,android,android-styles,Android,Android Styles,我不明白为什么在代码几乎相同的情况下,结果会有如此大的差异 两个按钮均使用相同的代码生成: int resId = (tile.getFormula() == null) ? R.layout.template_puzzle_result : R.layout.template_puzzle_formula; AppCompatButton button = (AppCompatButton) getActivity().getLayoutInflater().inflate(resId, p

我不明白为什么在代码几乎相同的情况下,结果会有如此大的差异

两个按钮均使用相同的代码生成:

int resId = (tile.getFormula() == null) ? R.layout.template_puzzle_result : R.layout.template_puzzle_formula;
AppCompatButton button = (AppCompatButton) getActivity().getLayoutInflater().inflate(resId, puzzleGrid, false);
    colorsNormal = ColorStateList.valueOf(getResources().getColor(R.color.tile_normal));
button.setSupportBackgroundTintList(colorsNormal);
它们是存储在android.support.v7.widget.GridLayout中的标准按钮。唯一的区别是样式属性

<Button
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_columnWeight="1"
    app:layout_rowWeight="1"
    app:layout_gravity="fill"
    style="@style/PuzzleTileResult"
/>
右边的按钮是:

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" >    
    <solid android:color="@color/colorPrimary" />
    <stroke
        android:width="30px"
        android:color="@color/green_215" />    
</shape>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" >    
    <solid android:color="@color/colorPrimary" />
    <stroke
        android:width="3px"
        android:color="@color/colorAccent" />    
</shape>

颜色:

<color name="tile_normal">#ffee00</color> - yellow
<color name="colorPrimary">#3F51B5</color> - blue
<color name="colorAccent">#FF4081</color> - pink
#ffee00-黄色
#3F51B5-蓝色
#FF4081-粉红色
我希望

  • 左按钮为30px厚的绿色边框和黄色内部
  • 右按钮为3倍厚的粉红色边框和黄色内部

但它的行为并不一致——左键从XML中获取内部颜色,右键从代码中获取内部颜色。左边的画有代码颜色,右边的画没有。为什么?

您的纯色是colorPrimary,而您的期望是黄色内饰。我用按钮覆盖它。setSupportBackgroundTintList(R.color.tile\u normal)哦,是的。您的着色模式是什么?默认值,因为我没有指定任何具体值。我无法理解左侧是矩形,而您的形状是椭圆形。色调与背景混合,所以不同的背景颜色会导致不同的表现。我找不到默认模式。是否尝试为AppCompatButton设置着色模式?比如屏幕?你的纯色是原色,而你的期望是黄色。我用按钮覆盖它。setSupportBackgroundTintList(R.color.tile_normal)哦,是的。您的着色模式是什么?默认值,因为我没有指定任何具体值。我无法理解左侧是矩形,而您的形状是椭圆形。色调与背景混合,所以不同的背景颜色会导致不同的表现。我找不到默认模式。是否尝试为AppCompatButton设置着色模式?比如屏幕?