1
votes

I need to instantiate semi-transparent Fragment with opaque (bold) buttons.

I'm trying to manage Fragment transparency by using alpha, like:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/templateListLayout"
    android:orientation="vertical"
    android:alpha="0.5"
    >
    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fabCustom"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:visibility="visible"
        app:elevation="4dp"
        app:borderWidth="1dp"
        app:fabSize="mini"
        android:layout_marginRight="24dp"
        android:layout_marginBottom="5dp"
        android:layout_marginLeft="5dp"
        android:layout_marginTop="5dp"
        android:layout_above="@id/anchor"
        android:layout_alignParentRight="true"
        android:alpha="1.0"
        />
    <View
        android:layout_width="fill_parent"
        android:layout_height="1dp"
        android:id="@+id/anchor"
        android:background="#000000"
        android:visibility="invisible"
        android:layout_alignParentBottom="true"
        />
</RelativeLayout>

But it's useless, Fragment becomes semi-transparent with button as well. But I need button to be non-transparent.

Fragment created as:

Fragment fragment = SelectTemplateFragment.newInstance();
getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, fragment).addToBackStack(null).commit();

Any ideas?

1

1 Answers

2
votes

The alpha value is inherited for child views. Instead try to place a background as a sibling of the buttons with the required alpha. Than have the buttons "above" it.

<RelativeLayout>
    <LinearLayout>
       Fill parent and alpha = X
    </LinearLayout>
    <Button>
       Placed wherever and alpha = 1
    </Button>
</RelativeLayout>