Android工作室 - 浮动按钮不响应任何事情 [英] Android studio - floating button dont respond to anything

查看:72
本文介绍了Android工作室 - 浮动按钮不响应任何事情的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个应用程序,在我实现了碎片后,我的浮动按钮突然没有响应任何东西。我已经尝试过再次使用所有指南,但这没有帮助。



我知道它有很多代码,但我真的不知道它有什么问题吗。

我的代码:



I'm making an app and after I implemented fragments my floating button suddenly don't respond to anything. I have tried using all the guides again but that didn't help.

I know it is alot of code, but i really dont have any idea whats wrong with it.
my code:

<pre><?xml version="1.0" encoding="utf-8"?>
<!-- Use DrawerLayout as root container for activity -->
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:app="http://schemas.android.com/apk/res-auto"

    android:id="@+id/drawer_layout"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:fitsSystemWindows="true"

    xmlns:tools="http://schemas.android.com/tools"

    tools:openDrawer="start">



    <android.support.v7.widget.Toolbar

        android:id="@+id/toolbar"

        android:layout_width="match_parent"

        android:layout_height="?attr/actionBarSize"

        android:background="#00FFFFFF"

        android:theme="@style/ThemeOverlay.AppCompat.ActionBar"

        android:elevation="4dp"/>
    <!-- Layout to contain contents of main body of screen (drawer will slide over this) -->
    <FrameLayout

        android:id="@+id/fragment_container"

        android:layout_width="wrap_content"

        android:layout_height="match_parent">


        <RelativeLayout

            android:layout_width="match_parent"

            android:layout_height="match_parent"

            android:layout_gravity="start">


            <RelativeLayout

                android:id="@+id/upper_section"

                android:layout_width="match_parent"

                android:layout_height="225dp"

                android:background="@drawable/bg">





                <TextView

                    android:layout_width="wrap_content"

                    android:layout_height="wrap_content"

                    android:layout_above="@+id/textView2"

                    android:layout_alignEnd="@+id/textView2"

                    android:text="0/25"

                    android:textColor="#ffffff"

                    android:textSize="30dp" />

                <TextView

                    android:id="@+id/textView2"

                    android:layout_width="wrap_content"

                    android:layout_height="wrap_content"

                    android:layout_alignParentBottom="true"

                    android:layout_alignParentEnd="true"

                    android:layout_marginBottom="33dp"

                    android:layout_marginEnd="26dp"

                    android:text="Gennemført"

                    android:textColor="@color/FontColor" />


            </RelativeLayout>


            <RelativeLayout

                android:id="@+id/test_id"

                android:layout_width="match_parent"

                android:layout_height="225dp"

                android:layout_marginEnd="150dp"

                android:background="@drawable/blue_line">

                <TextView

                    android:id="@+id/navn"

                    android:layout_width="wrap_content"

                    android:layout_height="69dp"

                    android:layout_alignParentStart="true"

                    android:layout_centerVertical="true"

                    android:layout_marginStart="20dp"

                    android:text="Name"

                    android:textColor="#ffffff"

                    android:textSize="30dp" />


                <TextView

                    android:id="@+id/text_view_date"

                    android:layout_width="wrap_content"

                    android:layout_height="wrap_content"

                    android:layout_alignParentBottom="true"

                    android:layout_alignStart="@+id/navn"

                    android:layout_marginBottom="14dp"

                    android:text="Torsdag den 7. juni 2018"

                    android:textColor="@color/FontColor"

                    android:textSize="12dp" />
            </RelativeLayout>

            <ListView

                android:id="@+id/listview"

                android:layout_width="386dp"

                android:layout_height="448dp"

                android:layout_alignParentStart="true"

                android:layout_below="@+id/textView3"

                android:layout_marginStart="6dp" />

            <TextView

                android:id="@+id/textView3"

                android:layout_width="wrap_content"

                android:layout_height="wrap_content"

                android:layout_alignParentStart="true"

                android:layout_below="@+id/upper_section"

                android:layout_marginBottom="10dp"

                android:layout_marginStart="20dp"

                android:layout_marginTop="10dp"

                android:text="Indkøbsliste"

                android:textColor="@color/Completed"

                android:textSize="15sp" />

            <android.support.design.widget.FloatingActionButton

                android:id="@+id/fab"

                android:layout_width="wrap_content"

                android:layout_height="wrap_content"

                android:layout_alignEnd="@+id/listview"

                android:layout_alignParentBottom="true"

                android:layout_gravity="end|bottom"

                android:layout_marginBottom="22dp"

                android:src="@drawable/ic_add"

                app:fabSize="normal" />

            <TextView

                android:id="@+id/textView"

                android:layout_width="wrap_content"

                android:layout_height="wrap_content"

                android:layout_alignParentBottom="true"

                android:layout_alignStart="@+id/textView3"

                android:layout_marginBottom="34dp"

                android:text="Completed"

                android:textColor="@color/Completed"

                android:textSize="15sp" />


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

        android:id="@+id/nav_view"

        android:layout_width="wrap_content"

        android:layout_height="match_parent"

        android:layout_gravity="start"

        android:fitsSystemWindows="true"

        app:headerLayout="@layout/nav_header"

        app:menu="@menu/drawer_view" />

</android.support.v4.widget.DrawerLayout>










public class MainActivity extends AppCompatActivity  implements NavigationView.OnNavigationItemSelectedListener{


    private DrawerLayout drawer;
    TextView fadetxt;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        drawer = findViewById(R.id.drawer_layout);
        fadetxt = findViewById(R.id.textView2);

        FloatingActionButton fab = findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Here's a Snackbar", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });
            //presentActivity(view);

        //Drawer
        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        drawer = findViewById(R.id.drawer_layout);
        NavigationView navigationView = findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);

        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar,
                R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.addDrawerListener(toggle);
        toggle.syncState();

            txtfade();



        Calendar calendar = Calendar.getInstance();
        String currentDate = DateFormat.getDateInstance(DateFormat.FULL).format(calendar.getTime());

        TextView textViewDate = findViewById(R.id.text_view_date);
        textViewDate.setText(currentDate);

        TextView nava = findViewById(R.id.navn);
        String s = "Navn"
                + System.getProperty("line.separator")
                + "Indkøbsliste"
                + System.getProperty("line.separator");


        nava.setText(s);
        txtfade();

    }





    //Text fade
    public void txtfade(){
        Animation animation = new AlphaAnimation(0.00f,1.00f);
        animation.setDuration(3000);
        animation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                fadetxt.setVisibility(View.INVISIBLE);
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                fadetxt.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });

        fadetxt.startAnimation(animation);

    }


    // Drawer Fragment Navigation

    @Override
    public boolean onNavigationItemSelected(@NonNull MenuItem item) {
        switch (item.getItemId()) {
            case R.id.nav_family:
                getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
                        new MessageFragment()).commit();
                break;
            case R.id.nav_settings:
                getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
                        new settingsFragment()).commit();
                break;
            case R.id.nav_madplan:
                getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
                        new familyFragment()).commit();
                break;
        }

        drawer.closeDrawer(GravityCompat.START);
        return true;
    }

    @Override
    public void onBackPressed() {
        if (drawer.isDrawerOpen(GravityCompat.START)) {
            drawer.closeDrawer(GravityCompat.START);
        } else {
            startActivity(new Intent(this,MainActivity.class));
        }
    }


    //Circular Reveal

    public void presentActivity(View view) {
        ActivityOptionsCompat options = ActivityOptionsCompat.
                makeSceneTransitionAnimation(this, view, "transition");
        int revealX = (int) (view.getX() + view.getWidth() / 2);
        int revealY = (int) (view.getY() + view.getHeight() / 2);

        Intent intent = new Intent(this, addItem.class);
        intent.putExtra(addItem.EXTRA_CIRCULAR_REVEAL_X, revealX);
        intent.putExtra(addItem.EXTRA_CIRCULAR_REVEAL_Y, revealY);

        ActivityCompat.startActivity(this, intent, options.toBundle());
    }
}





What I have tried:



I have already been searching the web but that didnt help



What I have tried:

I have already been searching the web but that didnt help

推荐答案

Your DrawerLayout is intercepting all the click events. You can prevent that by adding:
Your DrawerLayout is intercepting all the click events. You can prevent that by adding:
android:clickable="false"
android:focusable="false"


这篇关于Android工作室 - 浮动按钮不响应任何事情的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆