I'm new to android .I am now testing a TabView
with some text and Image . Image show but the text don't . android SDK version is 4.4.3 . Help me finding it please . I looked at many other places but none of it work for me .
This is the code :
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TabHost tabHost =(TabHost) findViewById(R.id.tabHost);
tabHost.setup();
TabHost.TabSpec spec=tabHost.newTabSpec("mitab1");
spec.setContent(R.id.tab1);
//spec.setIndicator("",getResources().getDrawable(android.R.drawable.ic_menu_rotate));
spec.setIndicator(prepareTabView("ABCD", R.drawable.talk));
TabHost.TabSpec spec1=tabHost.newTabSpec("mitab1");
spec1.setContent(R.id.tab2);
spec1.setIndicator(prepareTabView("CDEF", R.drawable.ball));
tabHost.addTab(spec);
tabHost.addTab(spec1);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
private View prepareTabView(String text, int resId) {
View view = LayoutInflater.from(this).inflate(R.layout.tabcustom, null);
ImageView iv = (ImageView) view.findViewById(R.id.TabImageView);
TextView tv = (TextView) view.findViewById(R.id.TabTextView);
iv.setImageResource(resId);
tv.setText(text);
return view;
}
This is tabcustom.xml:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/TabLayout"
android:padding="5dip"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="@+id/TabImageView"
android:src="@drawable/football"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/TabTextView"
android:text="Text"
android:paddingTop="5dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffffff"
/>