Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to get reference of the items in the Custom ActionBar
    primarykey
    data
    text
    <p>I am using a RelativeLayout with some items like EditTexts, Buttons to set a Custom ActionBar view. The problem is that I am unable to get the references of the items which are there in that custom view.</p> <p>Here is the custom view for ActionBar</p> <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@color/actionbar_background" android:gravity="fill_horizontal|center_horizontal" &gt; &lt;LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" &gt; &lt;LinearLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="2" android:gravity="center_horizontal" android:paddingTop="10dp" &gt; &lt;ImageButton android:id="@+id/ab_home" android:layout_width="47dp" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:paddingLeft="6dp" android:paddingRight="6dp" android:src="@drawable/home" /&gt; &lt;/LinearLayout&gt; &lt;View android:layout_width="1dp" android:layout_height="match_parent" android:alpha="0.2" android:background="@color/left_menu_background" /&gt; &lt;LinearLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="6" android:orientation="horizontal" &gt; &lt;LinearLayout android:id="@+id/ab_action_search" android:layout_width="match_parent" android:padding="7dp" android:layout_height="match_parent" android:orientation="horizontal" android:visibility="gone" &gt; &lt;EditText android:id="@+id/et_search" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/rounded_edittext" android:drawablePadding="8dp" android:drawableRight="@drawable/action_search_light" android:hint="Search" android:imeOptions="actionSearch" android:paddingLeft="5dp" android:singleLine="true" android:cursorVisible="false" android:textColor="#000000" android:textSize="15dp" /&gt; &lt;/LinearLayout&gt; &lt;LinearLayout android:id="@+id/ab_action_buttons" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" android:paddingTop="10dp" android:visibility="visible" &gt; &lt;Button android:id="@+id/btn_customAB_font" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:background="@null" android:text="@string/icon_font" android:textColor="#FFFFFF" android:textSize="10dp" /&gt; &lt;Button android:id="@+id/btn_customAB_tasks" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:background="@null" android:text="" android:textColor="#FFFFFF" android:textSize="25dp" /&gt; &lt;Button android:id="@+id/btn_customAB_search" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:background="@null" android:clickable="true" android:text="@string/icon_search" android:textColor="#FFFFFF" android:textSize="25dp" /&gt; &lt;/LinearLayout&gt; &lt;/LinearLayout&gt; &lt;View android:layout_width="1dp" android:layout_height="match_parent" android:alpha="0.2" android:background="@color/left_menu_background" /&gt; &lt;LinearLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="2" android:paddingTop="10dp" &gt; &lt;ImageView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:src="@drawable/ic_action_user" /&gt; &lt;/LinearLayout&gt; &lt;/LinearLayout&gt; &lt;/RelativeLayout&gt; </code></pre> <p>Here is how I inflate and <code>setCustomView</code> of the ActionBar.</p> <pre><code>ActionBar ab = getSupportActionBar(); ab.setDisplayShowCustomEnabled(true); ab.setDisplayHomeAsUpEnabled(false); ab.setDisplayShowHomeEnabled(false); ab.setDisplayUseLogoEnabled(false); ab.setCustomView(R.layout.custom_actionbar); inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); customActionBarView = inflater.inflate(R.layout.custom_actionbar,null); ImageButton ib = (ImageButton) customActionBarView.findViewById(R.id.ab_home); ib.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Log.d(TAG, "Home Clicked"); } }); </code></pre> <p>This log statement is never run. I Think I am using the <code>findViewById()</code> in a wrong way to reference the Buttons.</p> <p>Any help would greatly appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload