Note that there are some explanatory texts on larger screens.

plurals
  1. POMy tab widget doesn't display the picture icons
    primarykey
    data
    text
    <p>I'm trying to set up an app and I am happy with my progress. I've set up a tab widget as seen below which works fine, however the pictures I have set up are not displaying. This is confusing as I seem to have![enter image description here][1] all the right code. Any comments will be greatly revived :)</p> <p>So to review I am trying to put icons underneath each tab, for example a star under favourites and a clock under alerts etc...</p> <p>TrainMain.java</p> <pre><code>package com.tris.trainbuzzer; import android.app.TabActivity; import android.content.Intent; import android.content.res.Resources; import android.os.Bundle; import android.widget.TabHost; import android.widget.TabHost.TabSpec; @SuppressWarnings({ "deprecation" }) public class TrainMain extends TabActivity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_train_main); Resources res = getResources(); TabHost tabHost = getTabHost(); // Tab for planner TabSpec plannerspec = tabHost.newTabSpec("Planner"); plannerspec.setIndicator("Planner", res.getDrawable(R.drawable.icon_planner_tab)); Intent plannerIntent = new Intent(this, PlannerActivity.class); plannerspec.setContent(plannerIntent); // Tab for alerts TabSpec alertsspec = tabHost.newTabSpec("Alerts"); // setting Title and Icon for the Tab alertsspec.setIndicator("Alerts", res.getDrawable(R.drawable.icon_alerts_tab)); Intent alertsIntent = new Intent(this, AlertsActivity.class); alertsspec.setContent(alertsIntent); // Tab for settings TabSpec settingsspec = tabHost.newTabSpec("Settings"); settingsspec.setIndicator("Settings", res.getDrawable(R.drawable.icon_settings_tab)); Intent settingsIntent = new Intent(this, SettingsActivity.class); settingsspec.setContent(settingsIntent); // Tab for favourites TabSpec favouritesspec = tabHost.newTabSpec("Favourites"); favouritesspec.setIndicator("Favourites", res.getDrawable(R.drawable.icon_favourites_tab)); Intent favouritesIntent = new Intent(this, FavouritesActivity.class); favouritesspec.setContent(favouritesIntent); // Adding all TabSpec to TabHost tabHost.addTab(plannerspec); // Adding planner tab tabHost.addTab(favouritesspec); // Adding favourites tab tabHost.addTab(alertsspec); // Adding alerts tab tabHost.addTab(settingsspec); // Adding settings tab } } </code></pre> <p>activity_train_main.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;TabHost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent" &gt; &lt;LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" &gt; &lt;TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" /&gt; &lt;FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="fill_parent" /&gt; &lt;/LinearLayout&gt; &lt;/TabHost&gt; </code></pre> <p>icon_planner_tab.xml(in the drawable file)</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;!-- When selected, use grey --&gt; &lt;item android:state_selected="true" android:drawable="@drawable/planner_gray" &gt;&lt;/item&gt; &lt;!-- When selected, use white --&gt; &lt;item android:drawable="@drawable/planner_white"&gt;&lt;/item&gt; &lt;/selector&gt; </code></pre>
    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.
    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