2013-09-27 16 views
5

Mam aplikację, która ustawi tło dla obrazu z xml. Otrzymuję widok, dzwoniąc pod numer:Dodaj półprzezroczystą nakładkę do tła aktywności w środowisku wykonawczym

setContentView(R.) 

. Jak umieścić półprzezroczystą nakładkę na tym tle w czasie wykonywania, w zależności od warunku. Chciałbym mieć czerwoną nakładkę z ustawionym alfa na 50%.

Próbowałem utworzyć oddzielny plik xml z powielonym widokiem i innym obrazem/nakładką, ale jest brudny, ponieważ muszę nadmuchać wszystkie przyciski/widok tekstowy, kiedy używam nowego widoku.

dzięki matowe

[Edit1]

<?xml version="1.0" encoding="utf-8"?> 

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 
<LinearLayout android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/carefreebgscaledlighting" 
    android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android"> 


    <TextView 
     android:id="@+id/textviewcompanyname" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:textColor="#003F87" /> 

    <TextView 
     android:id="@+id/textViewYouAreSignedIn" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:layout_alignParentTop="true" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:textColor="#003F87" 
     /> 

      <TextView 
     android:id="@+id/textViewUnsentTransactions" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:layout_below="@id/textViewYouAreSignedIn" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:textColor="#003F87" 
     /> 

[Edit2]

<?xml version="1.0" encoding="utf-8"?> 


<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 


    <RelativeLayout 
     android:id="@+id/transparentOverlay" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:background="@color/red_transparent" > 


<LinearLayout android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/carefreebgscaledlighting" 
    android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android"> 




    <TextView 
     android:id="@+id/textviewcompanyname" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:textColor="#003F87" /> 

    <TextView 
     android:id="@+id/textViewYouAreSignedIn" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:layout_alignParentTop="true" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:textColor="#003F87" 
     /> 

[Edit3]

<?xml version="1.0" encoding="utf-8"?> 


<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 



<LinearLayout 
    android:id="@+id/ll1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/carefreebgscaledlighting" 
    android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android"> 




    <TextView 
     android:id="@+id/textviewcompanyname" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:textColor="#003F87" /> 

.

if(status.equalsIgnoreCase(IN)){ 

       youAreSignedInAt.setText("You are signed in at " + name); 
       LinearLayout layout =(LinearLayout)findViewById(R.id.ll1); 
       layout.setBackgroundResource(R.drawable.carefreebgscaledlightingred); 
      }else{ 

       youAreSignedInAt.setText("You are not signed in"); 
       LinearLayout layout =(LinearLayout)findViewById(R.id.ll1); 
       layout.setBackgroundResource(R.drawable.carefreebgscaledlighting); 
      } 
+0

Jeśli wiesz, jak nieprzejrzyste chcesz, dlaczego nie ma PNG? To będzie tylko jedno zdjęcie, które możesz dodać do układu, gdy zajdzie taka potrzeba. – Prmths

Odpowiedz

17

Off górze mojej głowie, można zadeklarować w tym kolor tła składnika alfa w pliku zasobów (tj colors.xml)

<color name="red_transparent">#66FF0000</color> 

a następnie umieścić widok (tzn RelativeLayout), na wierzchu resztą views.-

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <!-- All your views --> 

    <!-- Transparent layer --> 
    <RelativeLayout 
     android:id="@+id/transparentOverlay" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@color/red_transparent" /> 

</RelativeLayout> 

Wszystko, co musisz zrobić, to zmienia widoczność R.id.transparentOverlay jak chcesz.

+0

Witam wysłałem mój xml. jak widać, mam zestaw do rysowania jako tło. czy możliwe jest umieszczenie czerwonego odcienia nad tym ciągnięciem w czasie wykonywania. czy to właśnie robi twój kod? dzięki – turtleboy

+0

Jeśli chcesz, aby czerwona nakładka była na wierzchu wszystkiego, łącznie z twoim rysunkiem, tak, to właśnie powinien zrobić mój fragment. Jeśli po prostu chcesz zastosować czerwony filtr do swojej szuflady, to zupełnie inna historia. – ssantos

+0

Nadal, jeśli chcesz czerwoną nakładkę tuż nad drawable, możesz umieścić układ @ + id/transparentOverlay tuż nad widokiem, jeśli drawable. – ssantos

Powiązane problemy