Question

I have layer, it is transparent. I can click on button only, I want to click through layer.

Here's my Manifest:

<activity android:name=".Test" android:theme="@style/Theme.Transparent"/>

Here's Transparent theme style:

<style name="Theme.Transparent" parent="android:Theme">
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowIsFloating">true</item>
        <item name="android:backgroundDimEnabled">false</item>
</style>

Here's my Activity code:

import android.app.*;
import android.os.*;
import android.view.*;
import android.widget.*;

public class Test extends Activity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.test);

        // v I can touch through app, but cant click on button
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE); 
        // ^ I can touch through app, but cant click on button

        Button xclose = (Button) findViewById(R.id.buttonx);
        xclose.setOnClickListener(new View.OnClickListener() {
            public void onClick(View arg0) {
                finish();
            }
        });
    }
}

Here's my test.xml layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" >
    <Button android:id="@+id/buttonx" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:text="X" />
</RelativeLayout>
Était-ce utile?

La solution

Try this code and set click listener on the linear layout

        <?xml version="1.0" encoding="utf-8"?>
        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    
          android:layout_width="match_parent" android:layout_height="match_parent" >

         <LinearLayout android:layout_width="match_parent"    
            android:layout_height="wrap_content"
            android:id="@+id/ll">

           <Button android:id="@+id/buttonx" android:layout_width="wrap_content" 
           android:layout_height="wrap_content" android:layout_alignParentRight="true" 
           android:layout_alignParentTop="true" android:text="X" />
           </LinearLayout>
          </RelativeLayout>

Autres conseils

You already do the following here to set the click listener for the X button.

Button xclose = (Button) findViewById(R.id.buttonx);
    xclose.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            finish();
        }
    });

Now all you need to do is the same thing but for the Layout which you have created that is transparent. So that when you click the layout in the area that your play button is, it listens to the click, rather than the button, as the button is out of reach.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top