Android common UI Components

Source: Internet
Author: User

Android common UI Components
A Button is a commonly used UI component in Android, which is very small but most commonly used in development. Generally, it is used together with the listener to trigger some specific events. The Button inherits TextView. The function is to provide a button, which can be clicked by the user. When the user operates the button, the corresponding event is triggered, such as clicking and touching. Generally, the most commonly used Button is the click event, which indirectly inherits from the View. All events in the Android UI are defined in the View.

Instance: ButtonDemo
Running effect:



Code List:
Layout file: main. xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="vertical"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    >    <Button android:id="@+id/button1"        android:layout_width="fill_parent"        android:layout_height="wrap_content" android:text="Button1" />    <Button android:id="@+id/button2"        android:layout_width="fill_parent"        android:layout_height="wrap_content" android:text="Button2" /></LinearLayout>

Java source code file: ActivityButton. java
package com.rainsong.buttondemo;import android.app.Activity;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.Toast;public class ActivityButton extends Activity{    Button btn1;    Button btn2;        OnClickListener listener1;    OnClickListener listener2;    /** Called when the activity is first created. */    @Override    public void onCreate(Bundle savedInstanceState)    {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);        listener1 = new OnClickListener() {            public void onClick(View v) {                Toast.makeText(ActivityButton.this, "Button1 clicked",Toast.LENGTH_SHORT).show();            }        };        listener2 = new OnClickListener() {            public void onClick(View v) {                Toast.makeText(ActivityButton.this, "Button2 clicked",Toast.LENGTH_SHORT).show();            }        };        btn1 = (Button)findViewById(R.id.button1);        btn1.setOnClickListener(listener1);        btn2 = (Button)findViewById(R.id.button2);        btn2.setOnClickListener(listener2);    }}

API knowledge point
Activity

Public class
Activity
Extends ContextThemeWrapper
Implements ComponentCallbacks2 KeyEvent. Callback LayoutInflater. Factory2 View. OnCreateContextMenuListener Window. Callback

View findViewById (int id)
Finds a view that was identified by the id attribute from the XML that was processed in onCreate (Bundle ).

Void setContentView (int layoutResID)
Set the activity content from a layout resource.

View
Public class
View
Extends Object
Implements Drawable. Callback KeyEvent. Callback AccessibilityEventSource

Void setOnClickListener (View. OnClickListener l)
Register a callback to be invoked when this view is clicked.

Button
Public class
Button
Extends TextView

View. OnClickListener
Public static interface
View. OnClickListener

Abstract void onClick (View v)
Called when a view has been clicked.

Toast
Public class
Toast
Extends Object

Constants
Int LENGTH_LONG Showthe view or text notification for a long period of time.
Int LENGTH_SHORT Showthe view or text notification for a short period of time.

Static Toast
MakeText (Context context, int resId, int duration)
Make a standard toast that just contains a text view with the text from a resource.

Static Toast
MakeText (Context context, CharSequence text, int duration)
Make a standard toast that just contains a text view.
 
Void
Show ()
Show the view for the specified duration.

Has anyone introduced the third-party open-source android UI components?

Although the performance is different, the same can take effect. If you want to build a Fixed UI by yourself, you must use a low-level UI.

Has anyone introduced the third-party open-source android UI components?

Continue learning with patience. You have little knowledge about android. The problem you described does not exist. Be patient.
One step at a time.
Track: familiar with the controls provided by the android system-familiar with system controls, changing various control styles-in-depth study of source code, custom controls-.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.