0

I have Come across of a new requirement that am applying alpha for my parent layout using Frame layout. But what is the problem is I don't want to apply it for some of it's child elements like TextViews. How can I get this requirement.

<FrameLayout
            android:layout_width="fill_parent"
            android:orientation="vertical"
            android:layout_height="match_parent"
            android:minWidth="25px"
            android:minHeight="25px"
            android:alpha="0.2"
            android:layout_marginBottom="70dp"
            android:background="@drawable/login_border">
            <LinearLayout
                android:layout_width="fill_parent"
                android:orientation="vertical"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:layout_margin="0.7dp"
                android:layout_gravity="center_vertical"
                android:id="@+id/linearLayout4"
                android:background="#575757">
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_gravity="center"
                    android:gravity="center"
                    android:layout_marginRight="25dp"
                    android:layout_marginLeft="25dp"
                    android:id="@+id/linearLayout5">
                    <LinearLayout
                        android:layout_width="wrap_content"
                        android:orientation="vertical"
                        android:layout_gravity="center"
                        android:layout_height="wrap_content"
                        android:id="@+id/linearLayout6">
                        <LinearLayout
                            android:layout_width="wrap_content"
                            android:layout_gravity="center"
                            android:id="@+id/countryselect"
                            android:layout_height="wrap_content">
                            <TextView
                                android:layout_width="wrap_content"
                                android:text="+"
                                android:gravity="left"
                                style="@style/txtphonenumerSize"
                                android:id="@+id/txtPluseCode"
                                android:textColor="#ffffff"
                                android:layout_alignParentLeft="true"
                                android:layout_height="wrap_content"
                                android:padding="4dp" />
                            <TextView
                                android:id="@+id/txtCountryCode"
                                android:text="91"
                                android:layout_height="wrap_content"
                                android:layout_width="wrap_content"
                                android:maxLength="3"
                                android:singleLine="true"
                                android:textColor="#ffffff"
                                android:textSize="17dp"
                                android:paddingRight="10dp" />
                        </LinearLayout>
                    </LinearLayout>
                    <View
                        android:layout_width="0.5dp"
                        android:background="#ffffff"
                        android:layout_height="match_parent"
                        android:id="@+id/view1" />
                    <EditText
                        android:layout_width="match_parent"
                        android:textSize="16dp"
                        android:hint="Mobile Number"
                        android:id="@+id/txtMobileNumber"
                        android:gravity="left"
                        android:textColor="#ffffff"
                        android:maxLength="10"
                        android:textColorHint="#f9f9f9"
                        android:singleLine="true"
                        android:layout_height="wrap_content"
                        android:inputType="number"
                        android:background="@android:color/transparent"
                        android:padding="10dp">
                        <requestFocus
                            android:id="@+id/requestFocus2" />
                    </EditText>
                </LinearLayout>
                <View
                    android:layout_width="match_parent"
                    android:background="#ffffff"
                    android:layout_height="0.5dp"
                    android:id="@+id/view2" />
                <EditText
                    android:layout_width="fill_parent"
                    android:textSize="16dp"
                    android:gravity="left"
                    android:textColor="#ffffff"
                    android:textColorHint="#eeeded"
                    android:id="@+id/txtName"
                    android:maxLength="50"
                    android:singleLine="true"
                    android:layout_height="wrap_content"
                    android:hint="Name"
                    android:background="@android:color/transparent"
                    android:padding="10dp"
                    android:textStyle="bold" />
            </LinearLayout>
        </FrameLayout>
Nawin
  • 485
  • 8
  • 14

1 Answers1

1

You can try this:

yourParentView.getBackground().setAlpha(50);

I have set the opacity to 50, but you can use something between 0(fully transparent) or 255 (completely opaque).

Hope it helps.

Angelo Parente
  • 796
  • 2
  • 6
  • 15