3

以下示例适用于 android 4.1 但适用于 android 2.3 左右插图没有更改。这种行为的原因是什么?

public class MyFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.badges_fragment_layout, container, false);

    view.setBackgroundDrawable(getCustomDrawable());
    return view;
} 

private Drawable getCustomDrawable() {
    LayerDrawable layerDrawable = new LayerDrawable(new Drawable[]{getBottom(),     getTop()});
    layerDrawable.setLayerInset(1, 5, 0, 5, 0);
    return layerDrawable.mutate();
}

private Drawable getTop() {
    return new ColorDrawable(Color.parseColor("#ffffff"));
}

private Drawable getBottom() {
    return new ColorDrawable(Color.parseColor("#ff0000));
}
4

0 回答 0