SSブログ

ColorPickerDialogを使う [Dialog]

標準に用意されていないので、APIDemoにあるcom.example.android.apis.graphics.ColorPickerDialog を使います。

まず、ColorPickerDialog.java を自分のプログラムの任意のパッケージにコピーしてから。

ColorPickerDialog colorPickerDialog = new ColorPickerDialog(
        MainActivity.this,
        new ColorPickerDialog.OnColorChangedListener() {

            @Override
            public void colorChanged(int color) {
                //colorが選択された色

            }
        }, Color.BLACK);

colorPickerDialog.show();




ギャラリーから画像を取得する [Intent]

//呼び出す時

private static final int REQUEST_CODE_GALLERY = 99;

Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent, REQUEST_CODE_GALLERY);


//受け取る時


protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode != RESULT_OK)
        return;
    switch (requestCode) {
    case REQUEST_CODE_GALLERY:
        try {
            InputStream in = getContentResolver().openInputStream(
                    data.getData());
            Bitmap bitmap = BitmapFactory.decodeStream(in);
            in.close();
        } catch (Exception e) {

        }
        break;

    default:
        break;
    }
}





この広告は前回の更新から一定期間経過したブログに表示されています。更新すると自動で解除されます。