Android用のtabHostを使用するにはどうすればよいですか?
例に入る前に、Androidのタブホストとは何かを知っておく必要があります。タブホストはタブのセットを保持します。各タブには、プロジェクトの仕様に従ってフラグメントまたはアクティビティが含まれています。ユーザーはタブを左から右または右から左にスクロールできます。
この例は、Androidでタブホストを使用する方法を示しています。
ステップ1 − Android Studioで新しいプロジェクトを作成し、[ファイル]⇒[新しいプロジェクト]に移動して、新しいプロジェクトを作成するために必要なすべての詳細を入力します。
ステップ2 −次のコードを res / layout/activity_main.xmlに追加します。
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="https://schemas.android.com/apk/res/android" xmlns:app="https://schemas.android.com/apk/res-auto" xmlns:tools="https://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity"> <TabHost android:id="@+id/tabhost" android:layout_width="match_parent" android:layout_height="match_parent" > <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="fill_parent"> <LinearLayout android:id="@+id/tab1" android:layout_width="match_parent" android:layout_height="match_parent"> <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="tab1" /> </LinearLayout> <LinearLayout android:id="@+id/tab2" android:layout_width="match_parent" android:layout_height="match_parent"> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="tab2" /> </LinearLayout> </FrameLayout> </LinearLayout> </TabHost> </LinearLayout>
上記のレイアウトでは、フレームレイアウトをタブウィジェットの子として宣言しています(android.comによると、タブウィジェットのコンテンツとしてフレームレイアウトが必要でした)。
ステップ3 −次のコードをsrc / MainActivity.java
に追加しますimport android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.RadioButton;
import android.widget.TabHost;
public class MainActivity extends AppCompatActivity {
RadioButton radioButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TabHost tabs = (TabHost) findViewById(R.id.tabhost);
tabs.setup();
TabHost.TabSpec spec = tabs.newTabSpec("tag1");
spec.setContent(R.id.tab1);
spec.setIndicator("First");
tabs.addTab(spec);
spec = tabs.newTabSpec("tag2");
spec.setContent(R.id.tab2);
spec.setIndicator("second");
tabs.addTab(spec);
}
} ステップ4 −manifest.xmlファイルを変更する必要はありません。
アプリケーションを実行してみましょう。実際のAndroidモバイルデバイスをコンピューターに接続していると思います。 Android Studioからアプリを実行するには、プロジェクトのアクティビティファイルの1つを開き、ツールバーの[実行]アイコンをクリックします。オプションとしてモバイルデバイスを選択し、デフォルトの画面を表示するモバイルデバイスを確認します。
次に、2番目のタブをクリックします。以下に示すような結果が得られるはずです-
-
Android Phone を PC または TV のスピーカーとして使用する方法
世界のすべての良いものはペアで提供されます。塩とコショウ、ナイフとフォーク、トムとジェリー、テクノロジー愛好家向けのオーディオとビデオです。最先端のテクノロジーを手にしたとしても、オーディオとビデオの永続的な結合は、何十年もの間問題となってきました。 そんな時こそAndroidスマホのスピーカーが活躍します。音量の小さいラップトップ、サウンド システムに問題のあるテレビ、電源が切れた Bluetooth スピーカーなど、すべての解決策が手のひらの中にあります。信じられないかもしれませんが、Android フォンをスピーカーとして使用して、前述の問題を効果的に処理することができます。そんな時
-
WhatsApp for Android でステッカーを使用する方法
最近、iOS 13 は、アニ文字ステッカーのゲームを変える多くの機能をリリースしました。アニ文字は、非常に個人的なステッカーの束を提供します。この機能は iPhone 10 以降で利用でき、アニ文字は Face ID 機能で動作します。アニ文字ステッカーを使用して、ライブ ビデオや録画を作成できます。他の電話モデルでは、アバターを作成するオプションを提供するミー文字が利用可能ですが. したがって、これらのアニ文字とミー文字ステッカーは、WhatsApp、メッセージング アプリ、Facebook などの複数のプラットフォームで使用できます。これらのステッカーは iOS デバイス専用ですが、An