Kindle Fire上不显示标签

时间:2012-08-20 14:27:04

标签: tabs kindle

我有一个Android应用,它的开始菜单使用标签。将应用程序移植到Kindle Fire时,不会显示选项卡。这是代码:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView

    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:isScrollContainer="true" >

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <TabHost
        android:id="@+id/tabhost"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" >

            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" >
            </TabWidget>

            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="match_parent"
                android:layout_height="match_parent" >

                <LinearLayout
                    android:id="@+id/Beginning"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical" >
                </LinearLayout>

                <LinearLayout
                    android:id="@+id/Intermediate"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical" >
                </LinearLayout>

                <LinearLayout
                    android:id="@+id/Advanced"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical" >
                </LinearLayout>
            </FrameLayout>
        </LinearLayout>
    </TabHost>
</LinearLayout>

</ScrollView>
package com.myproject.project;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.content.res.AssetManager;
import android.database.Cursor;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.os.Environment;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.widget.TextView;
import android.widget.Toast;

public class TabsTestActivity extends Activity {
/** Called when the activity is first created. */

public static final String KEY_ROWID = "_id";
public static final String KEY_NAME = "name";
public static final String KEY_LEVEL = "level";
public static final String KEY_CHART = "charted";
public String extStorageDirectory = Environment
        .getExternalStorageDirectory().toString();

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    PopulateDatabase();

    CopyVideoFiles();

    TabHost tabhost = (TabHost) findViewById(R.id.tabhost);
    tabhost.setup();

    TabSpec spec_beg = tabhost.newTabSpec("Beginning");
    spec_beg.setContent(R.id.Beginning);
    TextView txtTabInfo = new TextView(this);
    txtTabInfo.setText("JUST STARTING");
    Typeface font = Typeface.createFromAsset(getAssets(), "danielbd.ttf");
    txtTabInfo.setTypeface(font);
    txtTabInfo.setGravity(Gravity.CENTER);
    txtTabInfo.setHeight(50);
    txtTabInfo.setBackgroundColor(Color.parseColor("#CCDE8A"));
    txtTabInfo.setTextColor(Color.parseColor("#262405"));
    spec_beg.setIndicator(txtTabInfo);

    TabSpec spec_int = tabhost.newTabSpec("Intermediate");
    spec_int.setContent(R.id.Intermediate);
    txtTabInfo = new TextView(this);
    txtTabInfo.setText("GETTING THERE");
    txtTabInfo.setTypeface(font);
    txtTabInfo.setGravity(Gravity.CENTER);
    txtTabInfo.setHeight(50);
    txtTabInfo.setBackgroundColor(Color.parseColor("#CCDE8A"));
    txtTabInfo.setTextColor(Color.parseColor("#262405"));
    spec_int.setIndicator(txtTabInfo);

    TabSpec spec_adv = tabhost.newTabSpec("Advanced");
    spec_adv.setContent(R.id.Advanced);
    txtTabInfo = new TextView(this);
    txtTabInfo.setText("REALLY GOOD");
    txtTabInfo.setTypeface(font);
    txtTabInfo.setGravity(Gravity.CENTER);
    txtTabInfo.setHeight(50);
    txtTabInfo.setBackgroundColor(Color.parseColor("#CCDE8A"));
    txtTabInfo.setTextColor(Color.parseColor("#262405"));
    spec_adv.setIndicator(txtTabInfo);

    // get data from database, create buttons and name them
    SQLData myTable = new SQLData(this);
    myTable.open();
    Cursor c = myTable.getallData();

    int iRow = c.getColumnIndex(KEY_ROWID);
    int iName = c.getColumnIndex(KEY_NAME);
    int iLevel = c.getColumnIndex(KEY_LEVEL);

    // create the buttons
    for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
        final String RowNum = c.getString(iRow);
        String Name = c.getString(iName);
        final String Level = c.getString(iLevel);
        Button button = new Button(this);
        button.setText(Name);
        button.setHeight(20);
        button.setTextColor(Color.BLACK);
        button.setBackgroundColor(Color.parseColor("#A89E0A"));
        button.setHighlightColor(Color.WHITE);
        button.setTypeface(font);
        button.setOnClickListener(new Button.OnClickListener() {

            public void onClick(View v) {
                Intent choice = new Intent(getApplicationContext

(),

                        com.myproject.project.myclass.class);
                Bundle dataBundle = new Bundle();
                dataBundle.putString("RowID", RowNum);
                dataBundle.putString("Level", Level);
                choice.putExtras(dataBundle);
                try {
                    startActivity(choice);
                } catch (Exception e) {
                    Dialog d = new Dialog(getApplicationContext());
                    d.setTitle("TabsTestActivity line 131");
                    TextView tv = new TextView(getApplicationContext());
                    tv.setText(e.toString());
                    d.setContentView(tv);
                    d.show();
                } finally {

                }
            }
        });

        LinearLayout lbeg = (LinearLayout) findViewById(R.id.Beginning);
        LinearLayout lint = (LinearLayout) findViewById(R.id.Intermediate);
        LinearLayout ladv = (LinearLayout) findViewById(R.id.Advanced);

        if (Level.equals("Beginning"))
            lbeg.addView(button);
        else if (Level.equals("Intermediate"))
            lint.addView(button);
        else if (Level.equals("Advanced"))
            ladv.addView(button);
    }

    tabhost.addTab(spec_beg);
    tabhost.addTab(spec_int);
    tabhost.addTab(spec_adv);

    myTable.close();

}}

有谁知道为什么?选项卡及其内容在模拟器和Android手机上显示正常。谢谢!

1 个答案:

答案 0 :(得分:1)

我已经了解到Kindle Fire不支持Tabs