gboyn
gboyn

Reputation: 71

Button does not appear clicked

I'm implementing a share option for my app. I built everything, and functionality-wise have no problems. My only problem is when I press the "share" buttons. Normally buttons change background color to slightly darker when you click them. However, my share buttons are not doing this and I have no idea why. Here is one of them:

<LinearLayout
    android:layout_width="75dp"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:id="@+id/text_share"
    android:layout_weight="1">

    <android.support.v7.widget.AppCompatImageView
         android:focusable="false"
         android:focusableInTouchMode="false"
         android:layout_width="65dp"
         android:layout_height="70dp"
         android:layout_marginTop="5dp"
         android:layout_gravity="center_horizontal"
         android:src="@drawable/icon_sms"
         android:scaleType="fitXY"
         android:background="@color/primaryDark" />

     <android.support.v7.widget.AppCompatTextView
         android:focusable="false"
         android:focusableInTouchMode="false"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_gravity="center_horizontal"
         android:text="SMS"
         android:textStyle="bold"
         android:textSize="14sp"
         android:textColor="#ffffff"/>
</LinearLayout>

And my JAVA reads:

View textShare = findViewById(R.id.text_share);
textShare.setOnClickListener(new View.OnClickListener(){
    @Override
    public void onClick(View view) {
        //share code here
    }
});

Upvotes: 0

Views: 25

Answers (1)

user5395084
user5395084

Reputation:

The answer is very simple and easy!

Make the LinearLayout clickable by adding android:clickable="true" to your LinearLayout's attributes.

Alternative answer

You don't need to use LinearLayout, you should create a regular Button and use android:drawableLeft and android:drawableStart to add images before text in a button, if you are trying to make a custom button, you can change the background, the text color, text size and other attributes. The file styles.xml will help you if you want to make your custom style global.

Upvotes: 1

Related Questions