adneal
adneal

Reputation: 30814

Would it be possible to let the user customize the color of a .9 drawable?

Pretty much what the title says. I'm wanting the user to have the choice to customize the boarder of a 9 drawable I have. Is something like that possible or do I need to use a different method? Right now, I think it won't work and it will mess up the 9 patch.

Upvotes: 0

Views: 140

Answers (2)

Josh
Josh

Reputation: 10738

Can you post a picture of your 9-patch? It might be possible to extract parts of it to another type of drawable, then layer the customizable part (drawn with user defined color) under the fixed portions using a layer-list.

[Update] Based on the pic you posted, I'd trash the layer list idea, but we can still work something out. The idea would be to remove the colored border and internal dark background from the 9-patch entirely (fill that area in with the shadow color and opacity). Then nest 3 layouts in each other. The first would use the 9-patch as a background. The second would use the user-defined color as a background. The third would use your panel color as a background. The 9-patch would provide the proper margins to position the second (user-color) layout, and then you'd just add a layout_margin attribute to the second panel to position the inner most layout a few dps in.

<LinearLayout
    android:id="@+id/PanelOuter"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/shadow_nine_patch">
    <LinearLayout
        android:id="@+id/PanelUserBorder"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/custom_border_width"
        android:background="@color/dialog_border_color_default">
        <LinearLayout
            android:id="@+id/PanelContent"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/custom_dialog_content_margin"
            android:background="@color/dialog_inner_color">
        </LinearLayout>
    </LinearLayout>
</LinearLayout>

Of course, you'd be responsible for finding the PanelUserBorder view in code and calling setBackgroundColor() with the proper user-defined color.

Upvotes: 1

Ian
Ian

Reputation: 3520

maybe you could tint it by putting a 50% transparent view overtop the button.

after thinking about it i thought maybe you could transform the color by bitmap:

How to change Bitmap image color in android?

Upvotes: 0

Related Questions