AndroidStudioのケース-アクティビティを開始する意図を表示する3つの方法
目次
アクティビティを開く意図を示す3つの方法。アクティビティを開始する方法については、次の記事を参照してください:
Android Studiocase-アクティビティインターフェースを開始します。
1つは、プロジェクトを作成する
- 以前にプロジェクトがない場合は、AndroidStudioの開始インターフェースで直接新しいプロジェクトを作成するだけです。
- プロジェクトがある場合は、[新規] ----> [新しいプロジェクト]をクリックします
次の操作プロセスについては、前の記事を参照してください[カタログの下のリンク]
作成後のプロジェクトインターフェース表示
これは、レイアウト(ビュー)作成イベントのログです。
特定のプロセスは上記のリンクの内容を参照でき、プロジェクトの作成を繰り返す必要はありません。
2つ目は、レイアウトを変更してボタンを追加することです。
レイアウト
追加ボタンの変更
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="intent的三种方式"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="方式一"
android:id="@+id/type1_btn"/>
<Button
android:id="@+id/type2_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="方式二"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="79dp" />
<Button
android:id="@+id/type3_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="方式三"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="154dp" />
画像対応説明
表示効果(実行または設計を選択できます)
実行
設計
3、時計と日付
時間制御タイムピッカーを配置します
<TimePicker
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
デザイン
場所カレンダーコントロール
<DatePicker
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
定義ボタンを設計し、インスタンス化します
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
Button type1_btn;
Button type2_btn;
Button type3_btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
type1_btn=(Button) findViewById(R.id.type1_btn);
type2_btn=(Button) findViewById(R.id.type2_btn);
type3_btn=(Button) findViewById(R.id.type3_btn);
type1_btn.setOnClickListener(this);
type2_btn.setOnClickListener(this);
type3_btn.setOnClickListener(this);
}
/**
* Called when a view has been clicked.
*
* @param v The view that was clicked.
*/
@Override
public void onClick(View v) {
Intent intent=new Intent();
switch (v.getId()){
case R.id.type1_btn:
intent.setClass(this,clock.class);
break;
case R.id.type2_btn:
intent.setClassName(this,"com.example.project.date");
break;
case R.id.type3_btn:
intent.setClassName("com.example.demo","com.example.demo.MainActivity");
break;
}
startActivity(intent);
}
インターフェイスコードの概要
4、関連するインポート
ボタン2 com.example.project.date
;
ボタン3:"com.example.demo","com.example.demo.MainActivity"
最初のもの:
上にリンクされたプロジェクトを開きます
2番目の
補足
5、効果のデモンストレーション
方法1
方法2
タップしてカレンダーを切り替えます。
方法3
6、要約および参考資料
1.まとめ
前回の記事の開始アクティビティを適用することで、今回の完了はかなり簡単です。