いくつかの単語の男は、マップ上の最初と
TextView:表示テキスト情報へのTextViewコントロール。
レイアウトプロパティ
|
機能説明
|
アンドロイド:layout_width
|
セット
のTextViewの
コントロールの幅
|
アンドロイド:layout_height
|
セット
のTextViewの
コントロールの高さ
|
アンドロイド:ID
|
セット
TextViewには、
固有の識別を制御します
|
アンドロイド:背景
|
セット
のTextViewの
バックグラウンドコントロール
|
アンドロイド:layout_margin
|
スクリーンコントロールの周りの電流制御または境界の距離を設定し、レイアウト
|
アンドロイド:パディング
|
セット
のTextViewの
制御内容との距離制御
|
アンドロイド:テキスト
|
設定テキスト
|
アンドロイド:の、textColor
|
テキストの色の表示を設定します
|
アンドロイド:TEXTSIZE
|
文字サイズを設定し、ユニットが推奨される
SP
|
アンドロイド:重力
|
テキスト位置を設定します。
|
アンドロイド:maxLengthを
|
設定したテキストの最大長は、このテキストの長さが表示されていない超え
|
アンドロイド:ライン
|
テキスト番号のテキスト行は、この行の数が表示されていない超え
|
アンドロイド:MAXLINES
|
テキストの行の最大数は、テキストのこの行数を超えて表示されません。
|
アンドロイド:ellipsize
|
テキストは、外部に設けられている場合
のTextView
所定の範囲が表示されます。
|
アンドロイド:drawableTop
|
テキスト表示画像の上で
|
アンドロイド:lineSpacingExtra
|
テキストのセット行間隔
|
アンドロイド:TEXTSTYLE
|
以下のようなテキストスタイルの設定、
太字
(ボールド)、
斜体
(イタリック)、
ノーマル
(ノーマル)
|
<TextViewの
アンドロイド:layout_width = "match_parent"
アンドロイド:layout_height = "wrap_content"
アンドロイド:テキスト=「テキストメッセージのTextView表示!」
アンドロイド:TEXTSIZE = "25dp"
アンドロイド:の、textColor = "#FF79E3"
アンドロイド:重力= "center_horizontal"
アンドロイド:TEXTSTYLE = "イタリック"
/>
ボタン:Buttonコントロールは、TextViewのコントロールからの継承は、テキストを表示することができますし、画像を表示することができますが、また、ユーザーがButtonコントロールがクリックされたときに、クリックして操作を実行することを可能にする、プレスやポップな背景があるだろうだけでなく、ボタンを表しダイナミックなトランジション効果、この効果は、効果をクリックします。
実装のボタンクリック時:
-
レイアウトファイル属性のonClick方法で、Buttonコントロール
①レイアウトファイルにonClick属性を指定:アンドロイド:のonClick =「クリック」
②活動でこれを達成するための方法をクリックします。
公共無効クリック(ビューV){
Log.i(「onClick属性指定モード」、「ボタンがクリックされました」);
}
-
匿名内部クラスの道
インテリア匿名のアクティビティに追加
btn.setOnClickListener(新しいView.OnClickListener(){
@オーバーライド
公共のボイドのonClick(ビューV){
Log.i(「匿名内部クラスの実施形態」、「ボタンがクリックされました」);
}
});
-
インターフェース
①Buttonコントロールのクリックリスナーイベント:btn.setOnClickListener(この);
:②現在活動インターフェースOnClickListener実現
パブリッククラスMainActivity AppCompatActivity実装View.OnClickListenerを拡張します③そしてOnClickListenerインターフェースの実装:
@Override公共ボイドのonClick(ビューV){Log.i( "インタフェース"、 "ボタンをクリックします") ;}
パッケージcom.example.controlcomponentdemo。
輸入androidx.appcompat.app.AppCompatActivity;
輸入android.os.Bundle;
輸入android.view.View;
輸入android.widget.Button;
パブリッククラスMainActivityは{AppCompatActivity実装View.OnClickListenerを拡張します
プライベートボタンボタン1。
プライベートボタンボタン2。
プライベートボタンボタン3;
@オーバーライド
保護されたボイドのonCreate(バンドルsavedInstanceState){
super.onCreate(savedInstanceState)。
setContentView(R.layout.activity_main)。
ボタン1 = findViewById(R.id.button1)。
ボタン2 = findViewById(R.id.button2)。
button2.setOnClickListener(新しいView.OnClickListener(){
@オーバーライド
公共のボイドのonClick(ビュービュー){
button2.setText(「2つのボタンがクリックされました」);
}
});
ボタン3 = findViewById(R.id.button3)。
button3.setOnClickListener(この);
}
公共無効クリック(ビュービュー){
button1.setText(「ボタンがクリックされました」);
}
@オーバーライド
公共のボイドのonClick(ビュービュー){
button3.setText( "ボタン3がクリックされました");
}
}
<ボタン
アンドロイド:layout_width = "wrap_content"
アンドロイド:layout_height = "wrap_content"
アンドロイド:テキスト=「の実装」
アンドロイド:ID = "@ + ID /ボタン1"
アンドロイド:のonClick = "クリック"
>
</ボタン>
<ボタン
アンドロイド:layout_width = "wrap_content"
アンドロイド:layout_height = "wrap_content"
アンドロイド:テキスト=「2の実装」
アンドロイド:ID = "@ + ID /ボタン2"
>
</ボタン>
<ボタン
アンドロイド:layout_width = "wrap_content"
アンドロイド:layout_height = "wrap_content"
アンドロイド:テキスト=「3の実装」
アンドロイド:ID = "@ + ID /ボタン3"
>
</ボタン>
結果:
EditText:のEditTextはのTextViewユーザのサブクラスであるエディットボックス、この制御で入力できる情報を表します。
プロパティ名
|
機能説明 |
アンドロイド:ヒント
|
プロンプトのテキストメッセージを表示するときにコントロールが空であります
|
アンドロイド:textColorHint
|
制御内容は、色、プロンプトテキスト情報の空に表示されます
|
アンドロイド:パスワード
|
テキストボックスに入力しますと表示されます「
」
|
アンドロイド:にphoneNumber
|
設定し、テキストボックスの内容は、唯一の番号を指定できます
|
アンドロイド:MinLines
|
テキストの行の最小数
|
アンドロイド:scrollHorizontally
|
テキスト情報を設定する超える
のEditTextに
クロスブレースがあるか否かを、ケースの幅
|
アンドロイド:編集可能
|
セット編集可能です
|
<のLinearLayout
アンドロイド:layout_width = "match_parent"
アンドロイド:layout_height = "match_parent"
アンドロイド:layout_marginTop = "140dp"
アンドロイド:オリエンテーション=「縦」>
<TextViewの
アンドロイド:layout_width = "wrap_content"
アンドロイド:layout_height = "wrap_content"
アンドロイド:テキスト= "姓名:"
アンドロイド:TEXTSIZE = "28SP"
アンドロイド:の、textColor = "#000000"
アンドロイド:TEXTSTYLE = "イタリック"
> </のTextView>
<のEditText
アンドロイド:layout_width = "wrap_content"
アンドロイド:layout_height = "wrap_content"
アンドロイド:ヒントは=「あなたの名前を入力してください。」
アンドロイド:MAXLINES = "2"
アンドロイド:の、textColor = "#000000"
アンドロイド:TEXTSIZE = "20SP"
> </のEditText>
</のLinearLayout>
ImageViewの:ImageViewの画像を表し、それはあなたがイメージのさまざまなリソースをロードすることができ、ビューから継承します。
プロパティ名
|
機能説明
|
アンドロイド:layout_width
|
セット
ImageViewのの
コントロールの幅
|
アンドロイド:layout_height
|
セット
ImageViewのの
コントロールの高さ
|
アンドロイド:ID
|
セット
ImageViewのは、
一意の識別を制御します
|
アンドロイド:背景
|
セット
ImageViewのの
バックグラウンドコントロール
|
アンドロイド:layout_margin
|
スクリーンコントロールの周りの電流制御または境界の距離を設定します。
|
アンドロイド:SRC
|
セット
ImageViewの
画像リソースのコントロールが表示されます
|
アンドロイド:scaleType
|
絵は、対応するリソースをズームしたり移動
ImageViewのは、
幅と高さを制御します
|
アンドロイド:ティント
|
指定した色に画像のレンダリング
|
<RelativeLayout
アンドロイド:layout_width = "match_parent"
アンドロイド:layout_height = "match_parent"
アンドロイド:layout_marginTop = "230dp">
<ImageViewの
アンドロイド:layout_width = "match_parent"
アンドロイド:layout_height = "400dp"
アンドロイド:背景= "@描画可能/ BG"
> </ ImageViewの>
<ImageViewの
アンドロイド:layout_width = "100dp"
アンドロイド:layout_height = "100dp"
android:src="@drawable/fo"
></ImageView>
</RelativeLayout>
RadioButton:RadioButton为单选按钮,android:checked属性指定是否选中的状态。
RadioGroup是单选组合框,可容纳多个RadioButton,并把它们组合在一起,实现单选状态。
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="430dp"
android:orientation="horizontal">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/man"
android:text="男"
android:textSize="28sp"
></RadioButton>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/woman"
android:text="女"
android:textSize="28sp"
></RadioButton>
<TextView
android:id="@+id/gendel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="你选择的性别是:"
></TextView>
</LinearLayout>
package com.example.controlcomponentdemo;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private RadioButton radioButton_man;
private RadioButton radioButton_woman;
private TextView textView;
radioButton_man = findViewById(R.id.man);
radioButton_woman = findViewById(R.id.woman);
textView = findViewById(R.id.gendel);
radioButton_man.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
textView.setText("您选择的性别是男!");
}
});
radioButton_woman.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
textView.setText("您选择的性别是女!");
}
});
}
}
CheckBox表示复选框,它是Button的子类,用于实现多选功能,通过android:checked属性指定CheckBox控件是否选中的状态。
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="460dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="请选择爱好:"
android:textSize="20sp"
>
</TextView>
<CheckBox
android:id="@+id/bassketball"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="篮球">
</CheckBox>
<CheckBox
android:id="@+id/football"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="足球">
</CheckBox>
<CheckBox
android:id="@+id/tennis"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="网球">
</CheckBox>
</LinearLayout>
Toast是Android系统提供的轻量级信息提醒机制,用于向用户提示即时消息,它显示在应用程序界面的最上层,显示一段时间后自动消失不会打断当前操作,也不获得焦点。
public class MainActivity extends AppCompatActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main)Toast.makeText(this,"Wifi已断开",Toast.LENGTH_LONG).show();
}
}