Basic controls and properties developed by Andriod

Control 1: TextView [2021 latest edition] Android (Android) develops zero-basics introductory course [full set] (created by millet, Ali, Tencent, IQIYI front-line factory teachers)_dairy dairy_bilibili

TextView is literally a text view, just for displaying text. It's called a label in iOS, or UILabel. To display TextView in an Activity,We need to add corresponding control labels in the corresponding layout file, which is the layout.xml file corresponding to the Activity. These XML labels can determine the location, size, color and other properties of the control. Below is a TextView displayed in the Activity.

Basic Properties

android:layout_width=""

android:layout_height=""

android:text=""

android:textColor=""

The style of the android:textStyle="" font

android:textSize="" font size

android:background=""textView background color

android:gravity="" position or layout of content

Shading TextView related content

android:shadowColor="#FF0000" sets the color of the shadow

android:shadowDx="3". Sets the offset of the shadow on the X-axis

android:shadowRadius="3.0" sets the width of the shadow

android:shadowDy="2". Sets the offset of the shadow on the Y-axis

The implementation of the related effects of the running lamp:

android:singleLine="true" single-line display
 android:focusable="true" whether to get focus
 android:focusableInTouchMode="true" touch condition to get focus
 Where does android:ellipsize="marquee" omit text
 android:marqueeRepeatLimit="marquee_forever" Subtitle Animation Repeats Number of Times
android:clickable="true"
<TextView
       android:layout_width="120dp"
       android:layout_height="wrap_content"
       android:layout_marginTop="30dp"
       android:background="@color/black"
       android:text="@string/text_1"
       android:textSize="16dp"
       android:singleLine="true"
       android:focusable="true"
       android:focusableInTouchMode="true"
       android:ellipsize="marquee"
       android:marqueeRepeatLimit="marquee_forever"
       android:clickable="true"
       />

Control 2: EditText EditText

The next step is to add an input box for the Activity. The type and label of the input box in Android are EditText. The input box in iOS is UITextField, which is similar in usage and function to receive user input data. Below is how the xml is laid out.

<EditText
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:hint="Full name"
        android:textSize="20dp"
        android:textColorHint="#FF0033"
        android:textColor="#FF0033"
        android:layout_marginLeft="16dp"
        android:maxLines="1"
        android:drawableLeft=""Add a picture to the left of the input box
        android:padding=""Set the distance between content and margin
        android:background=""background color
        android:inputType="text"Input data type
        />

hint property: set prompt

textColorHint: Set the color of the prompt

textColor: The color of the input word

maxLine: Maximum number of rows that can be entered

android:drawableLeft="" Add a picture to the left of the input box

android:padding="" sets the distance between content and margin

android:background="" background color

android:inputType="text" input data type

Control three: Button

Button is called Button in Android and UIButton in iOS. The usage of both buttons is very similar. Or similar to the above, we need to add a Button in the layout.xml corresponding to the Activity, and the specific XML code is shown below.

android:color="#000000"

android:state_pressed="false"

Is the android:state_checked="true" control checked

Whether android:state_focused="true" gets focus or not

Is android:state_enabled="true" space available

android:state_selected="true" space is selected for wheels

The implementation of Chang'an button discoloration:

selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/purple_700"  android:state_pressed="true"/>
    <item android:color="#3CC4C4"
        android:state_pressed="false"/>
</selector>

android:color="@color/purple_700". android:state_pressed="true" indicates how the button color changes when you press a button for a long time

android:color="@color/purple_700"; android:state_pressed="false" What color is the color of the off-time button

Three major events: click event, long press event, touch event.

Declare Control

Get control id

Create a corresponding event

  @Override
    protected void onCreate(Bundle savedInstanceState) {
        Button but1;
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_button);
        but1 = findViewById(R.id.button11);
       but1.setOnClickListener(new View.OnClickListener() {
               @Override
                public void onClick(View view) {
        //Click Event
                }
            });
         but1.setOnLongClickListener(new View.OnLongClickListener() {
             @Override
             public boolean onLongClick(View view) {
                 //Long press event
                 return false;
             }
         });
       but1.setOnTouchListener(new View.OnTouchListener() {
           @Override
           public boolean onTouch(View view, MotionEvent motionEvent) {
               return false;
               //Touch Events
           }
       });
    }

Control 4: AlterDialog (warning box)

Toast is used to display the prompt content, while AlterDialog is a warning box with controls such as buttons. AlterDialog is actually AlterView on iOS (with UIAlterController added after iOS8). The code below is the code that initializes AlterDialog and displays it, and the code below is placed in the method triggered by clicking a button.

(1) AlterDialog is created by AlterDialog's Builder, which, when created, specifies that the AlterDialog be displayed on that Activity.

(2) Title AlterDialog by setTitle method and content AlterDialog by setMessage.

(3) the setCancelable() method, which we set here as false, means that the pop-up AlterDialog does not disappear when the user clicks the return key, which defaults to true.

(4) The setPositiveButton() method is to set the event when the OK button is clicked. The setNegativeButton is to set the event when the Cancel button is clicked. Show the click of the event through Toast.

AlterDialog.Builder builer = new AlterDialog.Builder(this);Create first

Set title to AlterDialog via setTitle method

Set AlterDialog content through setMessage.

The setPositiveButton() method is to set the event when the OK button is clicked. The setNegativeButton is to set the event when the Cancel button is clicked. Show the click of the event via Toast.

 public void onlick(View view) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setIcon(R.mipmap.ic_launcher)
                .setTitle("I am a dialog box")
                .setMessage("What's the weather like today?")
                .setPositiveButton("Determine", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        Log.e(TAG, "onClick:Click OK");

                    }
                })
                .setNegativeButton("cancel", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        Log.e(TAG, "onClick: Clicked Cancel" );
                    }
                })
                .setNeutralButton("Middle", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        Log.e(TAG, "onClick:Middle Clicked " );
                    }
                })
                .create().show();
    }

Control 5: ProgressBar

A progress bar is a control that is commonly used to indicate the progress of a download. The UIProgressView in ProgressBar and iOS is similar and very similar. The layout and style of the ProgressBar need to be set in the Xml file corresponding to the Activity first. Below is the layout and style of the ProgressBar.

xml: 
<ProgressBar
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/ProgressBar"
    />
 <Button
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:text="Show hidden progress bar"
     android:onClick="ProgressBar"/>



java Code block:
public void ProgressBar(View view) {
        ProgressBar progressbar = findViewById(R.id.ProgressBar);
        if (progressbar.getVisibility()== view.GONE){
            progressbar.setVisibility(View.VISIBLE);
        }else{
            progressbar.setVisibility(view.GONE);
        }
    }

Control 6: Notification

 1.NotificationChannel channel

Channels for Notification, Android 8.0 introduces channels for Notification, which allows you to create user-defined channels for each type of notification you want to be realistic.

NotificationManager.IMPORTANCE_HIGH Open Notification pops up, sounds a prompt, and is displayed in the status bar

NotificationManager.IMPORTANCE_NONE Shutdown Notification

NotificationManager.IMPORTANCE_MIN Open Notification, does not pop up, but does not sound a prompt, and does not appear in the status bar

NotificationManager.IMPORTANCE_LOW Open Notification, no pop-up, no beep, status bar

NotificationManager.IMPORTANCE_DEFAULT Open Notification, does not pop up, sounds a prompt, and appears in the status bar

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
            NotificationChannel channel = new NotificationChannel("jiang", "Test Notification", NotificationManager.IMPORTANCE_MIN);
             manager.createNotificationChannel(channel);
        }

2. Create Notification Buider:

When creating Notifications, you can use the NotificationCompat.Builder object to specify the UI content of Notifications. A NotificationCompat.Builder object contains at least the following.

setColor Sets the color of the small icon

setLargeIcon Set Large Icon

setWhen Sets the time for notification

setContentIntent (pendingIntent intent) Sets the jump intent after a click event

setContentIntent usage:

Intent intent = new Intent(this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this,0,intent,0);

notification= new NotificationCompat.Builder(this,"jiang")
        .setContentTitle("Notification Title")
        .setSubText("The world is so big I want to see it")
        .setSmallIcon(R.drawable.abc_vector_test)
        .setContentIntent(pendingIntent)
        .build();

setAutoCancel() Sets the auto-clean notification after a click event

notification= new NotificationCompat.Builder(this,"jiang")
                .setContentTitle("Notification Title")
                .setSubText("The world is so big, I want to see it")
                .setSmallIcon(R.drawable.abc_vector_test)
                .setColor()
                .setLargeIcon()
                .setAutoCancel()
                .setWhen()
                .setContentIntent(PendingIntent intent)
                .build();

Note: When using setSmallIcon() to set small icons

android has modified the design of notification bar icons since the 5.0 system. Now Google requires that all application layer notification icons should only use alpha layers, not RGB layers.
3. Send:

manager.notify(1 ,notification);

Control 7: IamgeView

android:scaleType="centerInside"

center-related attributes and fit-related attributes.

android:scaleType="centerInside" The ultimate goal is to place the picture in the imageView, zooming in and out

android:scaleType="centerCrop"

android:scaleType="fitstart" keeps the aspect ratio of the picture scaled, knows that the longer edge is equal to the image view's edge, and places the scaled picture in the upper left corner.

android:scaleType="fitend". Zoom the picture in aspect ratio, knowing that the longer edges are equal to the imageView's, and place the zoomed picture in the lower right corner.

android:scaleType="fitcenter" keeps the aspect ratio of the picture scaled, knows that the longer edge is equal to the image view's edge, and places the scaled picture in the middle.

android:scaleType="fitXY" scales the picture horizontally, knowing that the picture fills the entire image, the ratio of length to width to height may be changed.

android:maxHeight="200dp" android:maxWeight="200dp"

android:adjustViewBounds="true

Control 8: Toolbar control

layout-width setting width

layout-height setting height

Background Sets the background color

APP:title Setting Title

APP:subtitle Set Subtitle

APP:subtitleTextColor Sets the color of the subtitle

Related properties can also be set in the java code block

Note the problem with the guide:

android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:background="#0CFFFF"
     app:navigationIcon=""
     app:title="Title"
     app:titleTextColor="#000000"
     app:subtitle="@string/text_1"
     app:subtitleTextColor="#FF3300"
     app:logo=""
     android:id="@+id/toolBar"






java Block:
 Toolbar toolbar = findViewById(R.id.toolBar);

             toolbar.setNavigationOnClickListener(new View.OnClickListener() {
                 @Override
                 public void onClick(View view) {
                     Log.e("loe", "onClick: toolbar Event" );
                 }
             });

Keywords: iOS Android html5

Added by Supplement on Wed, 06 Oct 2021 19:56:38 +0300