2011-10-08 5 views
3

Est-il possible de faire un bouton plein écran qui est transparent, peu importe où l'utilisateur clique sur le bouton est activé?Android - bouton plein écran transparent

est Ci-dessous quelques java de base qui affiche un bouton et lorsque vous appuyez commence une nouvelle intention. J'ai également ajouté la mise en page main.xml mais je ne suis pas sûr de savoir comment la mettre à jour pour que les boutons remplissent l'écran mais soient transparents.

package com.MeetingManager; 

import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.view.Window; 
import android.view.WindowManager; 
import android.widget.Button; 

public class MeetingManager extends Activity { 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

    requestWindowFeature(Window.FEATURE_NO_TITLE); 
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
          WindowManager.LayoutParams.FLAG_FULLSCREEN); 
    setContentView(R.layout.main); 



    layout.setOnTouchListener(new View.OnTouchListener() { 
     public boolean onTouch(View v, MotionEvent e) { 
      Intent myIntent = new Intent(MeetingManager.this,CreateMeeting.class); 
      startActivityForResult(myIntent, 0); 
     } 
    }); 

} 



} 

XML:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/meetingbg" 
    > 
    <TableRow android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/tableRow5"> 
     <Button android:text="Button" android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button> 
    </TableRow> 

</LinearLayout> 

Répondre

7

Si l'écoute de l'interaction utilisateur via tapotant sur l'écran est votre objectif, je recommanderais ajouté un auditeur contact à votre LinearLayout. Cela supprime le besoin d'un bouton.

E.g.

LinearLayout layout = (LinearLayout) findViewById(R.id.your_layout); 

layout.setOnTouchListener(new OnTouchListener() { 
     @Override 
     public boolean onTouch(View v, MotionEvent event) { 
      return false; 
     } 
    }); 
}); 

XML:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/your_layout" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/meetingbg" 
    > 
    <TableRow android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/tableRow5"> 
     <Button android:text="Button" android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button> 
    </TableRow> 

</LinearLayout> 

Vous devez inclure les importations suivantes:

import android.view.View.OnTouchListener; 
import android.view.MotionEvent; 

+0

Merci! +1 Je suis l'implémentation maintenant. – Denoteone

+0

Lorsque j'essaie d'ajouter le code ci-dessus, il essaie de réécrire mon fichier R.java (ce qui n'est pas possible) Ai-je raté quelque chose? J'ai mis à jour mon code ci-dessus. – Denoteone

+0

J'ai modifié ma source pour montrer comment ajouter un ID à votre mise en page dans le XML et comment l'attraper par programmation avant d'ajouter le onTouchListener. Espérons que cela aide – Ljdawson

1

essayez d'utiliser null en arrière-plan android:background="@null"

+0

Donc, pour supprimer le fond du bouton? Comment devrais-je obtenir le bouton pour superposer tous les autres éléments sur la page? – Denoteone

+0

vous pouvez utiliser RelativeLayout si vous avez un seul bouton vérifier aussi la méthode [bringChildToFront()] (http://developer.android.com/reference/android/view/ViewGroup.html#bringChildToFront%28android.view.View% 29) – salahy