spogebob92
spogebob92

Reputation: 1484

Buttons un-clickable in LinearLayout

I have 2 buttons in a LinearLayout, but they are un-clickable in their current layout. I have tried using breakpoints/Toasts to test and they are definitely not being pressed. I'm sure its something very simple. Here is the XML.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout  xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/Bjork">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/Bjork"
>

<android.support.v4.view.ViewPager
    android:id="@+id/viewpager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="290dp"
    android:fitsSystemWindows="true">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="250dp"
        android:background="#ffcc66"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        android:fitsSystemWindows="true"
        app:contentScrim="?attr/colorPrimary"
        app:expandedTitleMarginStart="48dp"
        app:expandedTitleMarginBottom="20dp"
        app:expandedTitleMarginEnd="64dp">

        <include layout="@layout/profile_header"
            android:layout_height="280dp"
            android:layout_width="match_parent"
            android:fitsSystemWindows="true"
            app:layout_collapseMode="parallax"/>

        <android.support.v7.widget.Toolbar
            android:id="@+id/anim_toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:layout_collapseMode="pin" />

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

    <android.support.design.widget.CollapsingToolbarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_scrollFlags="scroll|enterAlways"
        android:background="@color/Bjork">

        <android.support.design.widget.TabLayout
            android:id="@+id/sliding_tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            style="@style/tabLayout"
            android:background="@color/Bjork"
            />

    </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>




</android.support.design.widget.CoordinatorLayout>
<View
    android:id="@+id/background"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/Black"
    android:alpha="0"
    >
</View>

    <LinearLayout
    android:id="@+id/Dialog"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="150dp"
    android:background="@color/White"
    android:paddingLeft="@dimen/fab_margin"
    android:paddingRight="@dimen/fab_margin">

    <Button
        android:id="@+id/take_photo"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:text="Take Photo"
        android:background="@color/Transparent"
        android:textColor="@color/Black"
        android:drawableLeft="@drawable/ic_take_photo_black"
        android:drawablePadding="@dimen/fab_margin"
        android:padding="0dp"
        android:enabled="true"

        />
    <Button
        android:id="@+id/library"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:text="Library"
        android:background="@color/Transparent"
        android:textColor="@color/Black"
        android:drawableLeft="@drawable/library"
        android:drawablePadding="@dimen/fab_margin"
        android:padding="0dp"
        android:enabled="true"
        />
</LinearLayout>
</RelativeLayout>

And here is the Java code:

 takePhoto = (Button) findViewById(R.id.take_photo);
    takePhoto.setClickable(true);
    takePhoto.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dispatchTakePictureIntent();
        }
    });
Button library = (Button) findViewById(R.id.library);
library.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
        intent.setType("image/*");
        startActivityForResult(intent, RequestCodes.IMAGE_PICK);
    }
});

Upvotes: 1

Views: 221

Answers (1)

Irina Avram
Irina Avram

Reputation: 1522

Check wether there is something in front of them, or bring them to front with: library.bringToFront(); and takePhoto.bringToFront();

Update

takePhoto.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View view) {
        dispatchTakePictureIntent();
    }
});

Upvotes: 1

Related Questions