tags:

views:

25

answers:

1

I want to do this programatically:

<ImageView style="@style/TitleBarSeparator" />

Where TitleBarSeparator is:

<style name="TitleBarSeparator">
    <item name="android:layout_width">1px</item>
    <item name="android:layout_height">fill_parent</item>
    <item name="android:background">@color/title_separator</item>
</style>

I've tried:

new ImageView(getContext(), null, R.style.TitleBarSeparator);

but it doesn't work. I guess the error comes from passing null as AttributeSet but I am not completely sure.

A: 

I have found a way to fix it.

View v = new ImageView(getContext());
v.setLayoutParams(new LayoutParams(1, LayoutParams.FILL_PARENT));
v.setBackgroundColor(getContext().getResources().getColor(R.color.title_separator));

Still, I would like to have a way to set the style.

Macarse