George_BJ
George_BJ

Reputation: 606

Android: transparent activity does not work

I follow the suggestion from the below link How do I create a transparent Activity on Android? In HTC Desire the activity is transparent, but in Moto MileStone(Android), it doesnot work. THe background is black. I change the res/values/styles.xml as below, but the background in Moto MileStone is still black

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Transparent" parent="@android:style/Theme.Translucent.NoTitleBar">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@color/transparent</item>
<item name="android:colorBackgroundCacheHint">@null</item>
<item name="android:backgroundDimEnabled">false</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowNoTitle">true</item>
</style>
</resources>

Upvotes: 0

Views: 1386

Answers (3)

NewUser
NewUser

Reputation: 3819

Here is my solution:

My XML file which the first activity. After clicking on the button you will be redirected to the second activity which has a button. I am giving the complete source code:

Activity 1:

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Button nextBtn = (Button)findViewById(R.id.button1);
    nextBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            startActivity(new Intent("com.ranjan.dibya.shadow.Next"));
        }
    });
}
}

Activity 2:

public class Next extends Activity{

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.next);
}
}

XML for activity 1:

<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"
android:background="#f09473"
tools:context=".MainActivity" >

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_centerVertical="true"
    android:layout_marginRight="16dp"
    android:text="Button" />

 </RelativeLayout>

XML for Activity 2:

<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"
tools:context=".MainActivity" >

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:text="This is clickable" />

</RelativeLayout>

My Manifest

 <activity
        android:name=".Next"
        android:label="@string/app_name"
        android:theme="@style/Theme.MyTranslucent" >

Style:

<style name="Theme.MyTranslucent" parent="android:style/Theme.Translucent">
    <item name="android:backgroundDimEnabled">true</item>
    <item name="android:backgroundDimAmount">0.5</item>
    <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
    <item name="android:background">@android:color/transparent</item>
</style>

This works for me. I hope same will work for you.

Edit: The link you followed will result in a transparent activity with the buttons at the center figured this out by myself :)

Upvotes: 1

Wottah
Wottah

Reputation: 320

You could always try setting the RGBA value of your view programatically in the OnCreate method of your activity. That might work.

Upvotes: 1

divaNilisha
divaNilisha

Reputation: 693

I have not tried this but I think the best way to get transparent background is to add colors.

put transparent color in hexadecimal

http://www.w3schools.com/html/html_colornames.asp... you can check here .

click on right if you accept the answer.

any problem please post .

Upvotes: 0

Related Questions