Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is code how I create custom action bar with actiobBarSherlock</p> <pre><code> private void createCustomActionBar() { List&lt;SiteLink&gt; links = new ArrayList&lt;SiteLink&gt;(); links.add(...) LinksAdapter linkAdapter = new LinksAdapter(this, R.layout.external_link, links); View customNav = LayoutInflater.from(this).inflate(R.layout.custom_show_action_bar, null); IcsSpinner spinner = (IcsSpinner)customNav.findViewById(R.id.spinner); spinner.setAdapter(linkAdapter); ImageView refresh = (ImageView) customNav.findViewById(R.id.refresh); refresh.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ... } }); ImageView settings = (ImageView) customNav.findViewById(R.id.settings); settings.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ... } }); getSupportActionBar().setCustomView(customNav, new ActionBar.LayoutParams(Gravity.RIGHT)); getSupportActionBar().setDisplayShowCustomEnabled(true); } </code></pre> <p>Adapter</p> <pre><code>private static class LinksAdapter extends ArrayAdapter&lt;SiteLink&gt; { private List&lt;SiteLink&gt; strings; private Context context; private LinksAdapter(Context context, int textViewResourceId, List&lt;SiteLink&gt; objects) { super(context, textViewResourceId, objects); this.strings = objects; this.context = context; } @Override public int getCount() { if (strings == null) return 0; return strings.size(); } @Override public SiteLink getItem(int position) { return super.getItem(position); } // return views of drop down items @Override public View getDropDownView(int position, View convertView, ViewGroup parent) { final SiteLink siteLink = strings.get(position); LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); // at 0 position show only icon TextView site = (TextView) inflater.inflate(R.layout.external_link, null); site.setText(siteLink.getName()); site.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(siteLink.getUrl())); context.startActivity(i); } }); return site; } // return header view of drop down @Override public View getView(int position, View convertView, ViewGroup parent) { LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); return inflater.inflate(R.layout.icon, null); } } </code></pre> <p>Layout</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="right" &gt; &lt;com.actionbarsherlock.internal.widget.IcsSpinner android:id="@+id/spinner" android:layout_width="fill_parent" android:layout_height="fill_parent" android:paddingRight="20dp" android:layout_gravity="center" /&gt; &lt;ImageView android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/ic_navigation_refresh" android:paddingRight="20dp" android:paddingLeft="10dp" android:layout_gravity="center" android:background="@drawable/action_buttons_background" android:id="@+id/refresh"/&gt; &lt;ImageView android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/ic_action_settings" android:paddingRight="20dp" android:background="@drawable/action_buttons_background" android:layout_gravity="center" android:id="@+id/settings"/&gt; &lt;/LinearLayout&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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