public
Last active

Android - How to move ActionBar.Tab's icon as your needs (example using ActionBarSherlock)

  • Download Gist
PropositionListActivity.java
Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.ActionBar.Tab;
import com.actionbarsherlock.app.SherlockActivity;
 
import android.os.Bundle;
import android.app.Activity;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.ImageView;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.app.NavUtils;
 
public class PropositionListActivity extends SherlockActivity implements ActionBar.TabListener {
 
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.proposition_list);
getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
createTab(R.layout.tab_to_opine, R.id.tab_to_opine_title, "Vou Opinar");
createTab(R.layout.tab_opined, R.id.tab_opined_title, "Já Opinei");
createTab(R.layout.tab_feedback, R.id.tab_feedback_title, "Feedback");
}
public void createTab(int view, int titleView, String title) {
ActionBar.Tab tab = getSupportActionBar().newTab();
tab.setTabListener(this);
tab.setCustomView(view);
getSupportActionBar().addTab(tab);
((TextView) findViewById(titleView)).setText(title);
}
}
tab_to_opine.xml
XML
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
 
<ImageView
android:id="@+id/tab_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/tab_to_opine"
android:background="@android:color/transparent" />
 
<TextView
android:id="@+id/tab_to_opine_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
 
</LinearLayout>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.