用SeekBar做的Android顏色調色器,seekbarandroid

來源:互聯網
上載者:User

用SeekBar做的Android顏色調色器,seekbarandroid

1、介面布局xml代碼:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:id="@+id/LinearLayout1"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical"    tools:context=".MainActivity" >    <LinearLayout        android:layout_width="match_parent"        android:layout_height="wrap_content" >        <TextView            android:id="@+id/textView1"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="當前值是:#000000" />        <TextView            android:id="@+id/textView5"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:padding="20px"            android:width="100px"            android:text="test" />    </LinearLayout>    <LinearLayout        android:layout_width="match_parent"        android:layout_height="wrap_content" >        <TextView            android:id="@+id/textView2"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_weight="1"            android:text="紅:" />        <SeekBar            android:id="@+id/seekBar1"            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_weight="1"            android:max="255"            android:padding="10px"            android:progress="00" />        <EditText            android:id="@+id/editText1"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_weight="1"            android:text="0"            android:ems="10" >            <requestFocus />        </EditText>    </LinearLayout>    <LinearLayout        android:layout_width="match_parent"        android:layout_height="wrap_content" >        <TextView            android:id="@+id/textView3"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_weight="1"            android:text="綠" />        <SeekBar            android:id="@+id/seekBar2"            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:max="255"            android:progress="0"            android:layout_weight="1" />        <EditText            android:id="@+id/editText2"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_weight="1"            android:text="00"            android:ems="10" />    </LinearLayout>    <LinearLayout        android:layout_width="match_parent"        android:layout_height="wrap_content" >        <TextView            android:id="@+id/textView4"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_weight="1"            android:text="藍" />        <SeekBar            android:id="@+id/seekBar3"            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:max="255"            android:progress="0"            android:layout_weight="1" />        <EditText            android:id="@+id/editText3"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_weight="1"            android:text="00"            android:ems="10" />    </LinearLayout></LinearLayout>

2、java代碼:

package com.jwy;import android.os.Bundle;import android.R.integer;import android.R.string;import android.app.Activity;import android.graphics.Color;import android.view.Menu;import android.widget.EditText;import android.widget.SeekBar;import android.widget.Toast;import android.widget.SeekBar.OnSeekBarChangeListener;import android.widget.TextView;public class MainActivity extends Activity {private TextView textView;private SeekBar seekBar1;private SeekBar seekBar2;private SeekBar seekBar3;private EditText editText1;private EditText editText2;private EditText editText3;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        textView = (TextView)findViewById(R.id.textView1);        seekBar1 =(SeekBar)findViewById(R.id.seekBar1);        seekBar2 =(SeekBar)findViewById(R.id.seekBar2);        seekBar3 =(SeekBar)findViewById(R.id.seekBar3);                editText1=(EditText)findViewById(R.id.editText1);        editText2=(EditText)findViewById(R.id.editText2);        editText3=(EditText)findViewById(R.id.editText3);                seekBar1.setOnSeekBarChangeListener(new OnSeekBarChangeListener(){@Overridepublic void onStopTrackingTouch(SeekBar seekBar){// TODO Auto-generated method stub//Toast.makeText(MainActivity.this, "結束華滑動", Toast.LENGTH_SHORT).show();}@Overridepublic void onStartTrackingTouch(SeekBar seekBar){// TODO Auto-generated method stub//Toast.makeText(MainActivity.this, "開始滑動", Toast.LENGTH_SHORT).show();}@Overridepublic void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser){// TODO Auto-generated method stub//Toast.makeText(MainActivity.this, "當前值是:"+progress, Toast.LENGTH_SHORT).show();String str = String.format("%1$02x", progress);editText1.setText(str); doWork();}});                seekBar2.setOnSeekBarChangeListener(new OnSeekBarChangeListener(){@Overridepublic void onStopTrackingTouch(SeekBar seekBar){// TODO Auto-generated method stub}@Overridepublic void onStartTrackingTouch(SeekBar seekBar){// TODO Auto-generated method stub}@Overridepublic void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser){// TODO Auto-generated method stub//editText2.setText(Integer.toHexString(progress));editText2.setText(String.format("%1$02x", progress));doWork();}});                seekBar3.setOnSeekBarChangeListener(new OnSeekBarChangeListener(){@Overridepublic void onStopTrackingTouch(SeekBar seekBar){// TODO Auto-generated method stub}@Overridepublic void onStartTrackingTouch(SeekBar seekBar){// TODO Auto-generated method stub}@Overridepublic void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser){// TODO Auto-generated method stub//editText3.setText(Integer.toHexString(progress));editText3.setText(String.format("%1$02x", progress));doWork();}});    }    private void doWork(){    String sTmp = editText1.getText().toString()+ editText2.getText().toString() + editText3.getText().toString();textView.setText("當前值是:#" + sTmp);TextView tView = (TextView)findViewById(R.id.textView5);tView.setBackgroundColor(Color.parseColor("#"+sTmp));//tView.setBackgroundColor(Color.parseColor("#ff00"));}        @Override    public boolean onCreateOptionsMenu(Menu menu) {        // Inflate the menu; this adds items to the action bar if it is present.        getMenuInflater().inflate(R.menu.main, menu);        return true;    }    }



android 怎讓自己用圖片設計的圓形seekbar適應不同螢幕

兩個方法:
在drawable檔案夾中為不同的螢幕添加不同尺寸的圖片
只添加一個圖片,但是在dimens.xml中指定圖片的尺寸,在使用該圖片的地方按照尺寸使用代碼進行縮放

 
android開發中怎設定seekbar的最小值?

先設定:OnSeekBarChangeListener
然後:

@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if(progress < 70){
brightBar.setProgress(70);
return;
}
}
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.