Сенсорный приемник Android для CircularRevealCoordinatorLayout не работает - PullRequest
0 голосов
/ 07 марта 2019

Вот мой MainActivity.java

package com.example.android.dailyincomeandexpenses;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.viewpager.widget.ViewPager;

import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.widget.LinearLayout;
import com.example.android.dailyincomeandexpenses.Adapter.CatagoryAdapter;
import com.google.android.material.circularreveal.coordinatorlayout.CircularRevealCoordinatorLayout;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.tabs.TabLayout;

public class MainActivity extends AppCompatActivity {

LinearLayout editLayout;
CircularRevealCoordinatorLayout mainActivityLayout;
View view;
FloatingActionButton fab;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    goneEditLayoutWithTouch();
    editLayout=(LinearLayout)findViewById(R.id.edit_layout);
    editLayoutAnimation();
    // Adding Toolbar to Main screen
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    // Find the view pager that will allow the user to swipe between fragments
    ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);

    // Create an adapter that knows which fragment should be shown on each page
    CatagoryAdapter adapter = new CatagoryAdapter(this,getSupportFragmentManager());

    // Set the adapter onto the view pager
    viewPager.setAdapter(adapter);

    // Find the tab layout that shows the tabs
    TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);

    // Connect the tab layout with the view pager. This will
    //   1. Update the tab layout when the view pager is swiped
    //   2. Update the view pager when a tab is selected
    //   3. Set the tab layout's tab names with the view pager's adapter's titles
    //      by calling onPageTitle()
    tabLayout.setupWithViewPager(viewPager);

    // Adding Floating Action Button to bottom right of main view
   fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
           editLayout.animate().translationXBy(-1000).setDuration(500);
           fab.hide();
           //layoutTouchable();


        }
    });


}

//Top Menu bar
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater menuInflater=getMenuInflater();
    menuInflater.inflate(R.menu.topbar_menu,menu);
    return super.onCreateOptionsMenu(menu);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
     super.onOptionsItemSelected(item);
    switch(item.getItemId()){
        case R.id.searchAction:
            return true;
        case R.id.infoAction:
            return true;
        case R.id.settingsAction:
            return true;
        case R.id.aboutActions:
            return true;
        default:
            return false;
    }
}

//edit layout animation
public void editLayoutAnimation(){
    editLayout.setX(1000);
}

//when touch screen editlayout gone
public void goneEditLayoutWithTouch(){
    mainActivityLayout=(CircularRevealCoordinatorLayout) findViewById(R.id.main_activity_layout);
   mainActivityLayout.setOnTouchListener(new View.OnTouchListener() {
       @Override
       public boolean onTouch(View view, MotionEvent motionEvent) {
           editLayoutAnimation();
           fab.show();
           //layoutTouchUnable();
           return true;
       }
   });
}


}

Это мой код MainActivity.java. Я хочу, чтобы экран основной активности стал сенсорным. Когда я касаюсь экрана в любом месте, то выполняю какую-то работу или действие. Ноэтот код не работает. Пожалуйста, помогите мне кто-нибудь.Я новичок в Android. Я стараюсь много, но я не могу понять эту проблему.Теперь, как я могу решить эту проблему? Я думаю, что здесь весь мой код правильный, но не работает, почему?Здесь я использую CircularRevealCoordinatorLayout для своей основной деятельности.

...