标签主机在底部问题

时间:2016-07-30 19:21:47

标签: android android-tabhost android-theme tabwidget android-tabactivity

我在活动的底部有一个标签小部件,它包含一个图标和文字,但我的主题只显示文字。

我已经看到,这个问题发生在我当前的项目主题是“Theme.AppCompat.Light.NoActionBar”。而我使用“NOTITLEBAR”主题它工作正常但给我其他问题,因为我不能使用“没有标题栏”主题。

  

我真的不知道为什么会这样。请帮我找   错误。此外,欢迎提出建议。

TabWidget.xml

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@android:color/transparent"

    >
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
          android:background="@android:color/white"

     >
     <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="0dip"
            android:layout_weight="1"
              android:background="@android:color/white"


            />
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0"
            android:showDividers="middle"
            android:divider="@color/dividerColor"
              android:background="@color/button_color"
            android:tabStripEnabled="false"


             />

    </LinearLayout>
</TabHost>

TabActivity

public class MainActivity extends TabActivity {

    protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
             setContentView(R.layout.activity_main);

                    // stop executing code by return
                     return;
                }

            context = getApplicationContext();
               // TabHost tabHost = getTabHost();
                tabHost = getTabHost();
                SharedPreferences preferences2 = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
                String u_id1 = preferences2.getString("Userid","");
                Bean b = new Bean();
                b.setDeviceid(u_id1);

               // tabHost.getTabWidget().getResources().getDrawable(R.drawable.tab); 
             // Tab for Photos
                TabSpec photospec = tabHost.newTabSpec("Favourite");
                photospec.setIndicator("Favorites", getResources().getDrawable(R.drawable.tab_favourites));
            photospec.setContent(photosIntent);


            // Tab for Songs
                TabSpec songspec = tabHost.newTabSpec("Contacts");
                // setting Title and Icon for the Tab

                songspec.setIndicator("Contacts", getResources().getDrawable(R.drawable.tab_contacts));
                Intent songsIntent = new Intent(this, Contacts_new.class);
                songspec.setContent(songsIntent);

                // Tab for Videos
                TabSpec videospec = tabHost.newTabSpec("Meeting");
                videospec.setIndicator("Meeting",getResources().getDrawable(R.drawable.tab_meeting));
                Intent videosIntent = new Intent(this, Meeting.class);
                videospec.setContent(videosIntent);
             // Tab for Future SMS
                TabSpec futuresms = tabHost.newTabSpec("Map");
                futuresms.setIndicator("Map",getResources().getDrawable(R.drawable.tab_map));
                Intent futureIntent = new Intent(this, Map.class);
                futuresms.setContent(futureIntent);
                // Tab for Future SMS
                TabSpec setting = tabHost.newTabSpec("Setting");
                setting.setIndicator("Setting",getResources().getDrawable(R.drawable.tab_setting));
                Intent settingintent = new Intent(this, Setting.class);
                setting.setContent(settingintent);

            // Adding all TabSpec to TabHost
                tabHost.addTab(photospec); // Adding photos tab
                tabHost.addTab(songspec); // Adding songs tab
                tabHost.addTab(videospec); // Adding videos tab
                tabHost.addTab(futuresms);
                tabHost.addTab(setting);

            for (int j=0;j<tabHost.getTabWidget().getChildCount();j++){
                TextView textView = (TextView)tabHost.getTabWidget().getChildAt(j).findViewById(android.R.id.title);
                textView.setTextSize(5);

            }


            for (int i = 0; i <tabHost.getTabWidget().getChildCount(); i++) {
                tabHost.getTabWidget().getChildTabViewAt(i).setBackgroundColor(getResources().getColor(R.color.button_color));

            }

               String tabid = Bean.getDeviceid();
               if(tabid == null)
               {
                   int in = Integer.parseInt("2");
                    tabHost.setCurrentTab(in);
               }
               else
               {
                int in = Integer.parseInt(tabid);
                tabHost.setCurrentTab(in);
               }
             }  
        @Override
        protected void onDestroy() {
            // TODO Auto-generated method stub
             SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
              SharedPreferences.Editor editor = preferences.edit();
              editor.putString("msg","Hi");

            super.onDestroy();
        }



        @Override
        public void onBackPressed() {
            // TODO Auto-generated method stub
            super.onBackPressed();
            System.gc();
            MainActivity.this.finish();
            System.exit(0);
        }


    }

我使用的主题

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/green_top_bar</item>
        <item name="colorPrimaryDark">@color/green_top_bar</item>
        <item name="colorControlNormal">#ECEFF1</item>
        <!--<item name="colorAccent"></item>-->
        <item name = "android:textColorSecondary">#727272</item>

图片(显示问题):

enter image description here

1 个答案:

答案 0 :(得分:0)

这是因为底栏的高度让我们测试是否通过增加底栏的高度,然后确定你会看到图像。