Android Custom Toolbar is not clickable

android custom toolbar layout
androidx.appcompat.widget.toolbar example
android toolbar tutorial
android toolbar navigation icon
android.support.v7.widget.toolbar androidx
android toolbar height
android toolbar custom view example
android toolbar menu icon

I created a custom toolbar that has a "cancel" button on the left and "post" button on the write, a standard format that most social media apps use.

This is a portion of my xml code:

<androidx.appcompat.widget.Toolbar
    android:id="@+id/my_toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    style="@style/BarTheme"
    app:theme="@style/BarTheme"
    app:popupTheme="@style/AppTheme"
    app:layout_constraintTop_toTopOf="parent"
    android:background="@color/white"
    app:title="Lend"
    android:elevation="4dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <Button
            android:id="@+id/add_item_cancel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="left|center_vertical"
            android:textSize="15dp"
            android:fontFamily="sans-serif-condensed-light"
            android:background="@null"
            android:textColor="@color/grey"
            android:text="CANCEL"></Button>

        <TextView
            android:id="@+id/add_item_post"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:fontFamily="sans-serif-condensed-light"
            android:layout_gravity="bottom"
            android:textStyle="bold"
            android:gravity="center|center_vertical"
            android:textSize="30dp"
            android:text="NEW ITEM"></TextView>


        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="right|center_vertical"
            android:layout_weight="1"
            android:background="@null"
            android:fontFamily="sans-serif-condensed-light"
            android:textSize="15dp"
            android:layout_marginRight="16dp"
            android:textColor="@color/themeBlue"
            android:textStyle="bold"
            android:text="POST"></Button>
    </LinearLayout>
</androidx.appcompat.widget.Toolbar>

This is my style.xml code:

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/white</item>
    <item name="colorPrimaryDark">@color/white</item>
    <item name="colorAccent">@color/themeBlue</item>
</style>

<style name="BarTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/white</item>
    <item name="colorPrimaryDark">@color/white</item>
    <item name="colorAccent">@color/themeBlue</item>
</style>

</resources>

Now on the activity, I decided to at least try the "cancel" button, but it's not working. I tried to debug, but it doesn't even go into the function so I think it's not even clickable.

@Override
public void onClick(View view) {
    switch(view.getId()) {
        case R.id.add_item_cancel:
            Intent goBackIntent = new Intent(AddItemActivity.this, ListingsActivity.class);
            startActivity(goBackIntent);

    }
}

Thanks in advance for helping!

if you want to override onClick android says, that there is no corresponding method onClick to override. This just means, there is no global onClick, so nothing to override.

Add this to your cancel

android:onClick="cancel" 

and than in the code:

public void cancel(View v){
//test if works        
Log.d(TAG, "cancel: ");
}

Toolbar buttons not clickable � Issue #91 � henrytao-me/smooth-app , I created a toolbar with some imagebuttons, but click listener are not called for it. Here is my xml: can you CollapsingToolbarLayout android:id="@+id/ toolbar_layout" I tested custom button in Toolbar and it works normally. custom topBar button, not clickable #4553. Closed shakogele opened this issue Jan 9, 2019 · 6 comments For it to work on Android, along with visible:

Using the App Toolbar, The toolbar is not given any special treatment as a view. For more details about action items in the Toolbar including how to setup click Custom Title View. I created a toolbar with some imagebuttons, but click listener are not called for it. Here is my xml: can you help please. Maybe I set something wrong. &lt;android.support.design.widget.Coordinator

Ensure that you registered onclick listener on cancel button in onCreate or where you initialize the cancel button.

Like below:

addItemCancel.setOnClickListener(this);

Next implement the View.OnClickListener interface like below:

public class SettingsActivity extends BaseActivity implements View.OnClickListener{

.............

}

Then override the onclick method like below:

@Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.add_item_cancel:
                onBackPressed();
                break;
        }
    }

If you used the click listener on only one button or view then you can use the below code for click:

addItemCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });

For this you don't need to implement the View.OnClickListener interface.

I hope it helps you.

android.widget.Toolbar, An application may choose to designate a Toolbar as the action bar for an Activity One or more custom views. Interface responsible for receiving menu item click events if the items themselves do not have individual item click listeners. An example of this is a custom interface control that has two or more separately clickable areas, such as a calendar control. In this case, the services cannot get adequate information because the clickable subsections are not part of the view hierarchy. Figure 1. A custom calendar view with selectable day elements.

Android Custom Toolbar is not clickable, I created a custom toolbar that has a "cancel" button on the left and "post" button on the write, a standard format that most social media apps use. This is a portion � It is not on the item. A workable solution is to use the focusable attribute of the button. You need to assign false value to this attribute to avoid focusing on the button when the list is displayed. By doing this, you will be able to click the item of the list and the button.

Using Custom Views As Menu Items, The Android framework does a lot to help us create and interact with menu action items, those little icons on the right side of the toolbar. Adding a click listener to the view; Defining visual feedback when clicked (i.e. background instead of android:icon , onOptionsItemSelected will not be called for the custom menu item. Add a Custom ActionBar (Toolbar) - Android Studio Tutorial (Part 1) - Duration: 5:52. TechBrah 84,863 views. 5:52. Android tutorial: Option menu with dynamic items - Duration: 15:25.

4.1: Buttons and clickable images � GitBook, The user interface (UI) that appears on a screen of an Android-powered device Each button has three states: normal, disabled, and pressed. Choose Action Bar and Tab Icons in the drop-down menu. In this case, the app's look does not change when running on a device with a different default skin or custom skin. Hey. I am having this problem that happened recently on my windows 10 pc, some of the icons for example: the windows icon (bottom left), my volume control and wifi conection, time and calender and that notification thingy on bottom right are unclickable. although the hotbar on the bottom which contains things like: steam, chrome and someother stuff are clickable except I cant right click them.

Comments
  • can you post your activity code