オンタッチリスナーを使用してレイアウトのアルファ「カラー」を非アクティブ化する方法

プロジェクトX

こんにちは私はクイズアプリを作成しました。2番目のJavaクラス(Menu2)にはボタンがあります。誰かがこのボタンをクリックすると、ポップアップウィンドウが表示され、背景(Menu2のレイアウト)のアルファ/透明度は0.1になります。誰かがPOPUPWINDOWをクリックすると、ポップアップウィンドウが自動的に閉じ、透明度が1に設定されます。しかし、誰かがポップアップの外側をクリックすると、ポップアップは閉じますが、透明度は持続します...どうすれば修正できますか?

menu2:

        public class Menu2 extends AppCompatActivity {




private DrawerLayout mDrawerLayout2;
private ActionBarDrawerToggle mToggle;
private Toolbar mToolbar;
private Button popup;
private PopupWindow popupWindow;private LayoutInflater layoutInflater; //Alows to add a new layout in our window



@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_menu2);


     TextView txtScore = (TextView) findViewById(R.id.textScore2);
     TextView txtHighScore = (TextView)findViewById(R.id.textHighScore);
     ImageView imgTrophyView1 = (ImageView)findViewById(R.id.trophy1);
     ImageView imgTrophyView2 = (ImageView) findViewById(R.id.trophy2);
     TextView trophy1Txt = (TextView) findViewById(R.id.trophy1Text);
     TextView trophy2Txt = (TextView) findViewById(R.id.trophy2Text);

    Intent intent = getIntent();
    int mScore = intent.getIntExtra ("score",0);
    txtScore.setText("Your score is: " + mScore);

    SharedPreferences sharedpreferences = getSharedPreferences("mypref", Context.MODE_PRIVATE);
    int applyView =sharedpreferences.getInt("currentscore",0);


    SharedPreferences mypref =getPreferences(MODE_PRIVATE);
    int highScore = mypref.getInt("highScore", 0);
    if (highScore>= mScore)
        txtHighScore.setText("High score: " + highScore);


    else{
        txtHighScore.setText("New highscore: " + mScore);

        SharedPreferences.Editor editor = mypref.edit();
        editor.putInt("highScore",mScore);
        editor.commit();

    }

    if (applyView >=10) {
        imgTrophyView1.setVisibility(View.VISIBLE);
        trophy1Txt.setVisibility(View.VISIBLE);
    }
        if (applyView >= 20){
            imgTrophyView2.setVisibility(View.VISIBLE);
            trophy2Txt.setVisibility(View.VISIBLE);
    }


    popup = (Button)findViewById(R.id.enablePOPUP);
    popup.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            layoutInflater =(LayoutInflater) getApplicationContext().getSystemService(LAYOUT_INFLATER_SERVICE);
            ViewGroup container = (ViewGroup)layoutInflater.inflate(R.layout.popup_menu2_1,null);
            popupWindow = new PopupWindow(container,1000,980,true); //400,400=popUp size, true = makes that we can close the pop up by simply click out of the window
            popupWindow.showAtLocation(mDrawerLayout2, Gravity.CENTER, 0, 0);
            mDrawerLayout2.setAlpha((float) 0.1);

            container.setOnTouchListener(new View.OnTouchListener(){

                @Override

                        public boolean onTouch(View view, MotionEvent motionEvent  ){
                        mDrawerLayout2.setAlpha((float) 1);
                              popupWindow.dismiss();

                        return true;

                }
            });
        }
    });





    mToolbar = (Toolbar)findViewById(R.id.nav_action);
    setSupportActionBar(mToolbar);
    mDrawerLayout2 = (DrawerLayout) findViewById(R.id.drawerLayout2);

    mToggle = new ActionBarDrawerToggle(this, mDrawerLayout2, R.string.open, R.string.close);
    mDrawerLayout2.addDrawerListener(mToggle);
    mToggle.syncState();
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    NavigationView mNavigationView = (NavigationView) findViewById(nv2);
    mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {

        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem){
            switch (menuItem.getItemId()){
                case(R.id.nav_home2):
                    Intent accountActivity2 = new Intent(getApplicationContext(),QuizActivity.class);
                    startActivity(accountActivity2);

            }
            return true;
        }
    });}

            public void onClick(View view) {

                Intent intent = new Intent(Menu2.this, QuizActivity.class);
                startActivity(intent);

}




@Override //Makes that the "Burger" Item, shows the Drawer if someone clicks on the simbol
public boolean onOptionsItemSelected(MenuItem item) {
    if (mToggle.onOptionsItemSelected(item)) {
        return true;
    }
    return super.onOptionsItemSelected(item);


}

}

Menu2 XML:

      <?xml version="1.0" encoding="utf-8"?>
       <android.support.v4.widget.DrawerLayout 
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="amapps.impossiblequiz.Menu2"
        android:id="@+id/drawerLayout2">


<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">


    <include
        layout="@layout/navigation_action"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />


    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent">


        <TextView
            android:id="@+id/trophy2Text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="20 points= High knowledge"
            android:visibility="invisible"
            android:layout_alignTop="@+id/trophy1Text"
            android:layout_alignLeft="@+id/trophy2"
            android:layout_alignStart="@+id/trophy2"
            android:layout_alignRight="@+id/trophy2"
            android:layout_alignEnd="@+id/trophy2" />

        <TextView
            android:id="@+id/textScore2"
            android:layout_width="wrap_content"
            android:layout_height="50dp"
            android:background="#f60"
            android:paddingTop="10dp"
            android:paddingLeft="35dp"
            android:text="Your score is:"
            android:textAppearance="@style/TextAppearance.AppCompat"
            android:textColor="#ffffff"
            android:textSize="20dp"
            android:layout_marginTop="28dp"
            android:layout_below="@+id/textView2"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true" />

        <TextView
            android:id="@+id/textHighScore"
            android:layout_width="wrap_content"
            android:layout_height="50dp"
            android:background="#FFAB00"
            android:paddingLeft="35dp"
            android:paddingRight="100dp"
            android:paddingTop="10dp"
            android:text="Highest score:"
            android:textAppearance="@style/TextAppearance.AppCompat"
            android:textColor="#ffffff"
            android:textSize="20dp"
            android:layout_marginTop="13dp"
            android:layout_below="@+id/textScore2"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true" />

        <Button
            android:id="@+id/tryAgain_button"
            android:layout_width="150dp"
            android:layout_height="50dp"
            android:background="@drawable/bg_pill"
            android:onClick="onClick"
            android:text="Restart Quiz!"
            android:textColor="#ffffff"
            android:layout_marginTop="18dp"
            android:layout_below="@+id/textHighScore"
            android:layout_centerHorizontal="true" />

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="33dp"
            android:text="Stats: play and get trophies!"
            android:textAppearance="@style/TextAppearance.AppCompat.Button"
            android:textSize="20dp"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true" />

        <ImageView
            android:id="@+id/trophy1"
            android:layout_width="80dp"
            android:layout_height="80dp"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_below="@+id/tryAgain_button"
            android:layout_marginLeft="26dp"
            android:layout_marginStart="26dp"
            android:layout_marginTop="40dp"
            android:visibility="invisible"
            app:srcCompat="@drawable/trophy1" />

        <ImageView
            android:id="@+id/trophy2"
            android:layout_width="80dp"
            android:layout_height="80dp"
            android:layout_alignTop="@+id/trophy1"
            android:layout_marginLeft="24dp"
            android:layout_marginStart="24dp"
            android:layout_toEndOf="@+id/trophy1"
            android:layout_toRightOf="@+id/trophy1"
            android:visibility="invisible"
            app:srcCompat="@drawable/trophy2" />

        <TextView
            android:id="@+id/trophy1Text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="10 points= Basic intelligence"
            android:visibility="invisible"
            android:layout_below="@+id/trophy1"
            android:layout_alignLeft="@+id/trophy1"
            android:layout_alignStart="@+id/trophy1"
            android:layout_marginTop="23dp"
            android:layout_toLeftOf="@+id/trophy2"
            android:layout_toStartOf="@+id/trophy2" />

        <ImageView
            android:id="@+id/statsTrophy"

            app:srcCompat="@drawable/statsoftrophy"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_alignTop="@+id/textHighScore"
            android:layout_above="@+id/tryAgain_button"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true" />

        <Button
            android:id="@+id/enablePOPUP"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button"
            android:layout_below="@+id/trophy2"
            android:layout_alignRight="@+id/textView2"
            android:layout_alignEnd="@+id/textView2" />


    </RelativeLayout>


</LinearLayout>


<android.support.design.widget.NavigationView
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    app:menu="@menu/navigation_menu2"
    android:layout_gravity="start"
    android:id="@+id/nv2"
    app:headerLayout="@layout/navigation_header"
    app:itemIconTint="@drawable/tint_color_selector2">




</android.support.design.widget.NavigationView>

ブルーノ・フェレイラ

これを試してください:

popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {

    @Override
    public void onDismiss() {
        mDrawerLayout2.setAlpha((float) 1);
        popup.dismiss();

    }
});

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

PyQT5:ラジオボタンの状態でライン編集をグレーアウトして非アクティブ化する方法

分類Dev

cURLコマンドラインを使用して、リンクが非表示になっているファイルをダウンロードする方法(クリック時にのみアクティブ化)

分類Dev

インターフェイス型の配列プロパティを使用してオブジェクトをシリアル化する方法は?

分類Dev

マルチプロセッシングを使用してサブディレクトリ内の多数のファイルのラインアイテム頻度をカウントする方法

分類Dev

HP UFT 12.02:テストバッチランナーを使用してALMテストプランのファイルにアクセスする方法

分類Dev

サブディレクトリ内のRESXファイルを使用してWPFアプリケーションをローカライズする方法

分類Dev

wgetまたは他のツールを使用して、リンクが非表示になっているファイルをダウンロードする方法(クリック時にのみアクティブ化)

分類Dev

Delphiを使用してウィンドウの非クライアント領域でカスタムカーソルを使用する方法

分類Dev

Flutterのマテリアルスライダーウィジェットに新しいコールバックを追加して、タッチのアクティブ/非アクティブステータスにアクセスするにはどうすればよいですか?

分類Dev

SenseNetdotnetクライアントを使用してファイルアップロード後にカスタムフィールドを更新する方法

分類Dev

「text」属性を使用してファイルを正規化した後、gitにマスターブランチをチェックアウトさせ、キャリッジリターンを削除するにはどうすればよいですか?

分類Dev

インポートで.srcプレフィックスをディスペンスするSrcレイアウト?開発インストールのためにPyCharmターミナルでvenvをアクティブ化する

分類Dev

リモートインターネットトラフィックをブロックしますが、Windowsファイアウォールを使用してローカルコンピュータートラフィック(localhost)を許可します

分類Dev

Gsonを使用してJavaの非ネイティブフィールドを持つクラスをシリアル化する方法は?

分類Dev

Azureストレージアカウント、ファイルをダウンロードするためのパブリックリンクを使用してファイルをパブリックにします

分類Dev

サービスアカウントの認証情報を使用してGoogleドライブにファイルをアップロードする方法

分類Dev

COMインターフェイスを使用してCanOeのホットスポットを非アクティブ化する

分類Dev

シリアルを使用して、ライブラリ内のテンプレート化されたポリモーフィックタイプをシリアル化する

分類Dev

リストからファイルをスキップしながら、zipfileを使用してディレクトリの内容をアーカイブする

分類Dev

PowerShellでAzureストレージアカウントインフラストラクチャの暗号化ステータスを取得する方法

分類Dev

ファイルをマウントして、コンテナkubernetes内のアプリケーションからファイルにアクセスする方法

分類Dev

グーグルクラウドストレージクライアントがクラウドストレージ上の「ファイルオブジェクト」をポイントしてlxmlで使用する方法はありますか?

分類Dev

リンクが非表示になっているファイルをダウンロードするためにwgetまたは他のツールを使用する方法(クリック時にのみアクティブ化)

分類Dev

いくつかのトグルボタンを使用してリストボックスでフィルターをアクティブ化する

分類Dev

COLOR_ATTACHMENT's-フレームバッファオブジェクト内のカラーアタッチメントとして複数のテクスチャにレンダリングする方法は?

分類Dev

ナイトウォッチフレームワークを使用してフィールドをクリアする方法は?

分類Dev

インタラクティブストーリーシナリオでコンソールをクリアして特定のコードブロックを実行する方法

分類Dev

データバインディングライブラリを使用したMVVMアーキテクチャでタブレイアウトを使用する

分類Dev

サービスアカウントの認証情報を使用してGoogleCloud StorageNodeJSクライアントライブラリを初期化する方法

Related 関連記事

  1. 1

    PyQT5:ラジオボタンの状態でライン編集をグレーアウトして非アクティブ化する方法

  2. 2

    cURLコマンドラインを使用して、リンクが非表示になっているファイルをダウンロードする方法(クリック時にのみアクティブ化)

  3. 3

    インターフェイス型の配列プロパティを使用してオブジェクトをシリアル化する方法は?

  4. 4

    マルチプロセッシングを使用してサブディレクトリ内の多数のファイルのラインアイテム頻度をカウントする方法

  5. 5

    HP UFT 12.02:テストバッチランナーを使用してALMテストプランのファイルにアクセスする方法

  6. 6

    サブディレクトリ内のRESXファイルを使用してWPFアプリケーションをローカライズする方法

  7. 7

    wgetまたは他のツールを使用して、リンクが非表示になっているファイルをダウンロードする方法(クリック時にのみアクティブ化)

  8. 8

    Delphiを使用してウィンドウの非クライアント領域でカスタムカーソルを使用する方法

  9. 9

    Flutterのマテリアルスライダーウィジェットに新しいコールバックを追加して、タッチのアクティブ/非アクティブステータスにアクセスするにはどうすればよいですか?

  10. 10

    SenseNetdotnetクライアントを使用してファイルアップロード後にカスタムフィールドを更新する方法

  11. 11

    「text」属性を使用してファイルを正規化した後、gitにマスターブランチをチェックアウトさせ、キャリッジリターンを削除するにはどうすればよいですか?

  12. 12

    インポートで.srcプレフィックスをディスペンスするSrcレイアウト?開発インストールのためにPyCharmターミナルでvenvをアクティブ化する

  13. 13

    リモートインターネットトラフィックをブロックしますが、Windowsファイアウォールを使用してローカルコンピュータートラフィック(localhost)を許可します

  14. 14

    Gsonを使用してJavaの非ネイティブフィールドを持つクラスをシリアル化する方法は?

  15. 15

    Azureストレージアカウント、ファイルをダウンロードするためのパブリックリンクを使用してファイルをパブリックにします

  16. 16

    サービスアカウントの認証情報を使用してGoogleドライブにファイルをアップロードする方法

  17. 17

    COMインターフェイスを使用してCanOeのホットスポットを非アクティブ化する

  18. 18

    シリアルを使用して、ライブラリ内のテンプレート化されたポリモーフィックタイプをシリアル化する

  19. 19

    リストからファイルをスキップしながら、zipfileを使用してディレクトリの内容をアーカイブする

  20. 20

    PowerShellでAzureストレージアカウントインフラストラクチャの暗号化ステータスを取得する方法

  21. 21

    ファイルをマウントして、コンテナkubernetes内のアプリケーションからファイルにアクセスする方法

  22. 22

    グーグルクラウドストレージクライアントがクラウドストレージ上の「ファイルオブジェクト」をポイントしてlxmlで使用する方法はありますか?

  23. 23

    リンクが非表示になっているファイルをダウンロードするためにwgetまたは他のツールを使用する方法(クリック時にのみアクティブ化)

  24. 24

    いくつかのトグルボタンを使用してリストボックスでフィルターをアクティブ化する

  25. 25

    COLOR_ATTACHMENT's-フレームバッファオブジェクト内のカラーアタッチメントとして複数のテクスチャにレンダリングする方法は?

  26. 26

    ナイトウォッチフレームワークを使用してフィールドをクリアする方法は?

  27. 27

    インタラクティブストーリーシナリオでコンソールをクリアして特定のコードブロックを実行する方法

  28. 28

    データバインディングライブラリを使用したMVVMアーキテクチャでタブレイアウトを使用する

  29. 29

    サービスアカウントの認証情報を使用してGoogleCloud StorageNodeJSクライアントライブラリを初期化する方法

ホットタグ

アーカイブ