Android development - understanding palette

  In Android development, Google engineers have packaged a lot of buttons for us, which makes our development very convenient and convenient.

  So let's get to know the commonly used buttons today. I have already talked about the Button button in detail in the previous course, so I won't repeat it here.

  Android development-monitor button click event : http://www.cnblogs.com/xiao-chuan/p/6074075.html

 

1. Common buttons

  1. Button public properties

  The public attributes of the button include: 1) Commonly used style attributes

              a、background

              b、margin

              c、……

            2) width and height

              a、width

              b、height

            3) size

              a、size

              b、max(min)

              c、……

            4) Text display content

              a、text

              b、hint

            5) Unique key ID

              a、id

            6) Click event

 

  2、TextView:

    TextView: text box

    autoLink: the default path for the text

 

copy code
<TextView 
        android:layout_width="match_parent"
        android:layout_height="50sp"
        android:text="中国移动:10086"
        android:textSize="20sp"
        android:autoLink="phone"
        />
    <TextView 
        android:layout_width="match_parent"
        android:layout_height="50sp"
        android:text="站长邮箱:[email protected]"
        android:textSize="20sp"
        android:autoLink="email"
        />
    <TextView 
        android:layout_width="match_parent"
        android:layout_height="50sp" 
        android:autoLink="web"
        android:text="Look for Baidu: http://www.baidu.com"
        android:textSize="20sp"
        />
copy code

 

So here, if you click on the first TextView, the default effect is the phone, then what about the second and third ones~~ Here is the effect diagram of the realization, here you can see that I did not specify the text color, here is the attention autoLink has a default color!

 

 

 

  3、EditText

    EditText input box

    inputType: the text format of the input box

 

copy code
<EditText 
        android:id="@+id/userName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="请输入用户名"
        android:textColor="@android:color/holo_red_light"
        android:textSize="20sp"
        android:inputType="text"
        android:maxLength="12"
        />

    <EditText 
        android:id="@+id/userAge"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="请输入年龄"
        android:maxLength="3"
        android:numeric="integer"
        android:inputType="number"
        />
    <EditText 
        android:id="@+id/userPwd"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="请输入密码"
        android:maxLength="12"
        android:password="true"
        android:inputType="textPassword"
        />
    <EditText 
        android:id="@+id/userAddress"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="请输入详细地址"
        android:maxLength="500"
        android:lines="3"
        android:inputType="textMultiLine"
        />
copy code

 

  inputType:

    text: text format

    textPassword: password format

    number: number format

    textMultiLink: address bar format

    ……

  Note: When you type, the input method will automatically switch the input method. If you input in password format, the input content will not be visible.

  

  4、Bar

  Here are divided into:

    1) SeekBar: Scheduling, such as our volume, brightness, etc.

    2) RatingBar: Choose, the most common ones are comments on e-commerce websites, etc.

    3) ProgressBar: loading, downloading, loading pictures, downloading files, etc.

 

copy code
<TextView 
        android:id="@+id/showText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="我是一个TextView"
        android:textSize="20sp"
        />
    <SeekBar 
        android:id="@+id/seekBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:max="50"
        android:progress="20"
        />
    <RatingBar 
        android:id="@+id/ratingBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:numStars="5"
        android:rating="1"
        android:stepSize="1"
        />
    <ProgressBar
        android:id="@+id/progressBar" 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:max="100"
        android:progress="10"
        />
    <ProgressBar
        android:id="@+id/progressBar2" 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:max="100"
        android:progress="10"
        style="?android:attr/progressBarStyleLarge"
        />
    <ProgressBar
        android:id="@+id/progressBar3" 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:max="100"
        android:progress="10"
        style="?android:attr/progressBarStyleHorizontal"
        />
    <LinearLayout android:layout_width="match_parent"
        android:layout_height="wrap_content" android:orientation="horizontal">
        <Button 
            android:layout_width="0dp" 
            android:layout_weight="1"
            android:layout_height="wrap_content" 
            android:text="开始"
            android:onClick="doStart"
            />
        <Button 
            android:layout_width="0dp" 
            android:layout_weight="1"
            android:layout_height="wrap_content" 
            android:text="end" 
            android:onClick="doStop" 
            /> 
    </LinearLayout>
copy code

 

  Page effect:

 

 

  The following is to make everyone more clear about their effects and differences:

 

copy code
private SeekBar sb;
    private TextView showText;
    private RatingBar rb;
    private ProgressBar pb3;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_seek_bars);

        showText=(TextView)findViewById(R.id.showText);
        sb=(SeekBar)findViewById(R.id.seekBar);
        rb=(RatingBar)findViewById(R.id.ratingBar);
        pb3=(ProgressBar)findViewById(R.id.progressBar3);
        //为seekBar绑定事件
        sb.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
            }
            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
            }
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress,
                    boolean fromUser) {
                //改变showText字体大小
                showText.setTextSize(progress);
            }
        });

        rb.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
            @Override
            public void onRatingChanged(RatingBar ratingBar, float rating,
                    boolean fromUser) {
                Toast.makeText(SeekBarsActivity.this, "You have selected"+rating+"star", 3000).show(); } 
            }
        ); 
    } 

    //Start downloading [Note: Except ProgressBar, all UI must be in the UI main thread Middle operation] 
    boolean isRun=true; 
    public void doStart(View view) throws Exception{ 
        isRun=true; 
        //Build a sub-thread that executes progress bar changes 
        new Thread(new Runnable() {     
            @Override 
            public void run() { 
                / /Time-consuming operations cannot be executed in the main thread 
                while(isRun){ 
                    if(pb3.getProgress()<100){ 
                        pb3.setProgress(pb3.getProgress()+1); 
                        try { 
                            Thread.sleep(50);
                        } catch (InterruptedException e) { 
                            e.printStackTrace(); 
                        }
                    }else{ 
                        isRun=false; 
                        //The easiest way to update the UI in multiple threads 
                        runOnUiThread(new Runnable() { 
                            public void run() { 
                                Toast.makeText(SeekBarsActivity.this, "Download complete",3000).show() ; 
                            } 
                        }); 
                    } 
                } 
            } 
        }).start(); 
    } 
    //end download 
    public void doStop(View view){ 
        isRun=false; 
    }
copy code

 

Note: 
  1) Except ProgressBar, all UI must be operated in the UI main thread, otherwise an error will be reported
  2) Time-consuming operations cannot be performed in the main thread, otherwise an error will be reported.
  
  3) Google engineers have made Android 4.0 and later versions not support the above two points, so some people will be entangled. The one who maintains a low version needs to How to do ~ ~ think for yourself, very simple question!

 

 

   

  

  5. Image and single-selection multiple-selection boxes

    1) imageButton: image button

    2) imageView: image view

            ImageView compared with HTML5:

            imageView: It runs more smoothly and can be used without a network. .

            HTML5: The runtime is not smooth enough, and it will be useless without the Internet... But the advantage is that the page is more beautiful and the data transmission is more convenient. .

 

    3) RadioButton: radio button, each element is mutually exclusive, only one can be selected, such as gender

    4) CheckBox: Multi-choice button, you can choose multiple, such as hobbies

    5) ToggleButton: a single prompt button, such as a switch

copy code
<RadioGroup android:id="@+id/rgsex" 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <RadioButton 
            android:id="@+id/sexOne"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="男" 
            android:checked="true"
            />
        <RadioButton 
            android:id="@+id/sexTwo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="女"
            />
    </RadioGroup>
    <LinearLayout android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <CheckBox 
            android:id="@+id/cb1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="篮球"
            />
        <CheckBox 
            android:id="@+id/cb2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="football" 
            android:id="@+id/cb3"
        <CheckBox
            />
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="羽毛球"
            />
    </LinearLayout>

    <ToggleButton 
        android:id="@+id/stateButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textOn="开灯"
        android:textOff="关灯"
        android:checked="true"
        />
    <ImageButton 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/image001"
        android:scaleType="fitXY"
        android:maxWidth="120dp"
        android:maxHeight="60dp"
        android:adjustViewBounds="true"
        android:onClick="getValues"
        />
copy code

 

   The effect is as follows:

 

 

  ps: The picture is coded because I can't find a suitable picture and I don't want to advertise to others and I don't have money...

  

 

   The following is also to make their effects and differences more clear:

 

copy code
private RadioGroup rg;
    private CheckBox cb1,cb2,cb3;    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_buttons);

        cb1=(CheckBox)findViewById(R.id.cb1);
        cb2=(CheckBox)findViewById(R.id.cb2);
        cb3=(CheckBox)findViewById(R.id.cb3);
        rg=(RadioGroup)findViewById(R.id.rgsex);
        //监听单选按钮组事件
        rg.setOnCheckedChangeListener(new OnCheckedChangeListener() {    
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                RadioButton rb=(RadioButton)findViewById(checkedId); 
                Toast.makeText(ButtonsActivity.this, "You selected:"+rb.getText().toString(), 3000).show(); } } 
            ) 
        ; 
    } 

    // Value[radio button | check box] 
    public void getValues(View view){ 
        //radio button 
        RadioButton rb=(RadioButton)findViewById(rg.getCheckedRadioButtonId()); 
        StringBuffer sb=new StringBuffer(); 
        sb.append ("Gender:"+rb.getText().toString()+"\n"); 

        // checkbox 
        sb.append("Hobby:"); 
        if(cb1.isChecked()) 
            sb.append(cb1 .getText().toString()+","); 
        if(cb2.isChecked()) 
            sb.append(cb2.getText().toString()+","); 
        if(cb3.isChecked()) 
            sb.append(cb3.getText().toString()+",");
        Toast.makeText(this, sb.toString(), 5000).show();
    }
copy code

  

  PS: Google engineers have packaged it for us, and we can use it directly. We can also write a low-level framework to implement these buttons. I believe that you have already written the implementation of these buttons when you are learning Java. In fact, the underlying code encapsulated by Google engineers is also implemented in that way. Just saying~ who is so boring? Ready-made ones don't need it! But if you do Android framework development in the future... you need to write it yourself~ After the basic knowledge is updated...it will involve more advanced content hahahaha...not ready yet!

 

2. Summary

  1. In fact, there are many commonly used ones and some not commonly used ones. Anyway, I hope everyone can develop the habit of self-study... especially in the company!

  2. The development of the Android framework is simply Java knowledge, so it has nothing to do with Android development, but it also requires a high understanding of Android!

  3. It can be nested in Android pages, but it is necessary to distinguish the difference between HTML5 and Android palette!

  4. The difference between TextView and EditView is actually very big...

  5. Palette is really meaningful only when it is used together with corresponding events and business logic, such as data transmission~~ I will explain it in detail in future courses.

 

Guess you like

Origin blog.csdn.net/qq_33505204/article/details/78451830