0

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.

adneal
  • 30,484
  • 10
  • 122
  • 151
  • Why do you need this choice? How does user (not developer) interact with your application? Does user load some .9-images to your application? – Andrei Buneyeu Aug 10 '11 at 13:20
  • I don't need it, I want it, just to be clear. The idea is to give the user the ability to change the color of a boarder on a pop-up box in my application. The pop-up box drawable needs to be a nine-patch however. – adneal Aug 10 '11 at 14:02

2 Answers2

1

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.

Josh
  • 10,618
  • 2
  • 32
  • 36
  • Yarb, here's my Dropbox link. It should be obvious what I'm wanting to change. http://dl.dropbox.com/u/2301775/gingerbread.png I like your idea, by the way. – adneal Aug 10 '11 at 16:27
  • Edited my answer based on your comment. – Josh Aug 10 '11 at 17:37
  • Yeah, I'm going to go ahead and called this solved. I've got a much better idea going about this now. – adneal Aug 10 '11 at 18:01
0

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?

Community
  • 1
  • 1
Ian
  • 3,500
  • 1
  • 24
  • 25
  • Hmm. Yeah, I may have to end up doing something a little tricky like that. Not a bad idea. – adneal Aug 10 '11 at 14:03
  • i think the best way to do this is to make 1 few different 9 patches yourself, and then let the user pick. – Ian Aug 10 '11 at 14:38
  • Ha, yeah. That's actually what I've already done. I've just kinda run out of colors and I wanted to give a customizable one in that case. – adneal Aug 10 '11 at 14:44