Android Toastの継続時間をToast.LENGTH_LONGより長く設定するにはどうすればよいですか?
この例は、AndroidToastの継続時間をToast.LENGTH_LONGより長く設定する方法を示しています。
ステップ1 − Android Studioで新しいプロジェクトを作成し、[ファイル]⇒[新しいプロジェクト]に移動して、新しいプロジェクトを作成するために必要なすべての詳細を入力します。
ステップ2 −次のコードをres / layout/activity_main.xmlに追加します。
<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout 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" tools:context=".MainActivity"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" /> <androidx.appcompat.widget.AppCompatButton android:layout_width="match_parent" android:layout_height="match_parent" android:onClick="showToast"/> </androidx.constraintlayout.widget.ConstraintLayout>
ステップ3 −次のコードをsrc / MainActivity.java
に追加しますpackage com.app.sample;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.View;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
private Toast mToastToShow;
public void showToast(View view) {
int toastDurationInMilliSeconds = 10000;
mToastToShow = Toast.makeText(this, "Hello world, I am a toast.", Toast.LENGTH_LONG);
CountDownTimer toastCountDown;
toastCountDown = new CountDownTimer(toastDurationInMilliSeconds, 1000 /*Tick duration*/) {
public void onTick(long millisUntilFinished) {
mToastToShow.show();
}
public void onFinish() {
mToastToShow.cancel();
}
};
mToastToShow.show();
toastCountDown.start();
}
} ステップ4 −次のコードをManifests / AndroidManifest.xml
に追加します<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="https://schemas.android.com/apk/res/android" package="com.app.sample"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
アプリケーションを実行してみましょう。実際のAndroidモバイルデバイスをコンピューターに接続していると思います。 Android Studioからアプリを実行するには、プロジェクトのアクティビティファイルの1つを開き、ツールバーの[実行]アイコンをクリックします。オプションとしてモバイルデバイスを選択し、デフォルトの画面を表示するモバイルデバイスを確認します-
-
Android に Microsoft Teams をインストールしてセットアップする方法
Covid-19 のパンデミックは予想外で不確実なものでしたが、それに伴って私たちの職場文化に多くの変化がもたらされました。そのような変化の 1 つが、在宅勤務現象の真っ只中でのオンライン コミュニケーション ツールの台頭でした。これにより、Microsoft の主力オンライン コミュニケーション アプリである Teams の新規サブスクリプションが大幅に増加しました。統計オタクの場合、このアプリは現在、2019 年の 2,200 万人のユーザーから増加して、2 億 7,000 万人の定期ユーザーを誇っています。 この需要の大幅な増加に伴い、アプリは当然、相互互換性を維持しようとするため、さ
-
Outlook for Android アプリでメールを設定する方法
Outlook は、何十年にもわたって最も人気のあるメール管理ソリューションの 1 つであり、世界中の複数の個人や企業によって使用されています。コンピューターで電子メールにアクセスするために使用する主要なツールかもしれませんが、スマートフォンについて話すときは確かに同じではありません.しかし、Android スマートフォンで Outlook を構成するのは非常に簡単で、数分で完了します。どのクライアントよりも優れた方法で電子メールを整理するだけでなく、スパマーや犯罪者があなたに到達するのを困難にします.したがって、読者がAndroidでOutlookをセットアップする方法を学ぶことは価値があり