下面列出了android.widget.ImageButton# setImageBitmap ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private static void initHomeNavbar(LinearLayout homeNavbar, final ViewPager vp) {
XpLog.i("initHomeNavbar");
Context context = homeNavbar.getContext();
ImageButton btnCall = new ImageButton(context);
btnCall.setImageBitmap(ImageUtil.byte2Bitmap(DataHook.mapImgRes.get(ConstantStr.FUNC_SMALL_POINT_CODE)));
btnCall.setScaleType(ImageView.ScaleType.FIT_CENTER);
btnCall.setBackgroundColor(Color.alpha(255));
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT);
homeNavbar.addView(btnCall, params);
setHomePointPosition(homeNavbar);
btnCall.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
vp.setCurrentItem(2);
}
});
}
private void cargar(int posicion) {
Amigo amigo = MainActivity.listaAmigos.get(posicion);
EditText etNombreApellidos = (EditText) findViewById(R.id.etNombreApellidos);
EditText etEmail = (EditText) findViewById(R.id.etEmail);
EditText etTelefonoFijo = (EditText) findViewById(R.id.etTelefonoFijo);
EditText etFechaNacimiento = (EditText) findViewById(R.id.etFechaNacimiento);
EditText etTelefonoMovil = (EditText) findViewById(R.id.etTelefonoMovil);
EditText etDedudas = (EditText) findViewById(R.id.etDeudas);
ImageButton ibFoto = (ImageButton) findViewById(R.id.ibFoto);
etNombreApellidos.setText(amigo.getNombreApellidos());
etEmail.setText(amigo.getEmail());
etTelefonoFijo.setText(amigo.getTelefonoFijo());
etFechaNacimiento.setText(String.valueOf(amigo.getFechaNacimiento()));
etTelefonoMovil.setText(amigo.getTelefonoMovil());
etDedudas.setText(String.valueOf(amigo.getDeudas()));
ibFoto.setImageBitmap(amigo.getFoto());
}
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
if ((requestCode == RESULTADO_CARGA_IMAGEN) &&
(resultCode == RESULT_OK) && (data != null)) {
// Obtiene el Uri de la imagen seleccionada por el usuario
Uri imagenSeleccionada = data.getData();
String[] ruta = {MediaStore.Images.Media.DATA};
// Realiza una consulta a la galería de imágenes solicitando la imagen seleccionada
Cursor cursor = getContentResolver().query(imagenSeleccionada,
ruta, null, null, null);
cursor.moveToFirst();
// Obtiene la ruta a la imagen
int indice = cursor.getColumnIndex(ruta[0]);
String picturePath = cursor.getString(indice);
cursor.close();
// Carga la imagen en el botón ImageButton
ImageButton ibFoto = (ImageButton)
findViewById(R.id.ibFoto);
ibFoto.setImageBitmap(BitmapFactory.decodeFile(picturePath));
}
}
@Override
public void onActivityCreated(Bundle savedInstanceState)
{
super.onActivityCreated(savedInstanceState);
if (savedInstanceState != null)
{
View rootView = getView();
tabHost.setCurrentTabByTag(savedInstanceState.getString("tab"));
iconValue = savedInstanceState.getString("icon");
ImageButton icon = (ImageButton) rootView.findViewById(R.id.icon_button);
if (iconValue != null)
{
Androzic application = Androzic.getApplication();
Bitmap b = BitmapFactory.decodeFile(application.markerPath + File.separator + iconValue);
if (b != null)
icon.setImageBitmap(b);
}
else
{
icon.setImageDrawable(getResources().getDrawable(R.drawable.ic_highlight_remove_white_24dp));
}
}
}
private ViewGroup getPanel(Context context, int type) {
final ViewGroup mViewGroup = new LinearLayout(context);
LinearLayout.LayoutParams btnParam =
new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
// btnParam.weight = 1;
btnParam.gravity = Gravity.CENTER_VERTICAL;
LinearLayout.LayoutParams seekBarParam =
new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
seekBarParam.weight = 1;
seekBarParam.gravity = Gravity.CENTER;
ImageButton btnBack = new ImageButton(context);
btnBack.setImageBitmap(backBitmap);
btnBack.setScaleType(ImageView.ScaleType.FIT_CENTER);
btnBack.setBackgroundColor(Color.alpha(255));
SeekBar seekBar = getSeekBar(context, type);
ImageButton btnFunc = new ImageButton(context);
btnFunc.setImageBitmap(funcBitmap);
btnFunc.setScaleType(ImageView.ScaleType.FIT_CENTER);
btnFunc.setBackgroundColor(Color.alpha(255));
mViewGroup.addView(btnBack, btnParam);
mViewGroup.addView(seekBar, seekBarParam);
mViewGroup.addView(btnFunc, btnParam);
final WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
mViewGroup.setBackgroundColor(Color.BLACK);
btnBack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
wm.removeView(mViewGroup);
}
});
return mViewGroup;
}
/**
* Builds an {@link ImageButton} from the data in this params. Generated buttons should be
* placed on the bottom bar. The button's tag will be its id.
* @param parent The parent that the inflated {@link ImageButton}.
* @param listener {@link OnClickListener} that should be used with the button.
* @return Parsed list of {@link CustomButtonParams}, which is empty if the input is invalid.
*/
ImageButton buildBottomBarButton(Context context, ViewGroup parent, OnClickListener listener) {
if (mIsOnToolbar) return null;
ImageButton button = (ImageButton) LayoutInflater.from(context)
.inflate(R.layout.custom_tabs_bottombar_item, parent, false);
button.setId(mId);
button.setImageBitmap(mIcon);
button.setContentDescription(mDescription);
if (mPendingIntent == null) {
button.setEnabled(false);
} else {
button.setOnClickListener(listener);
}
button.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
final int screenWidth = view.getResources().getDisplayMetrics().widthPixels;
final int screenHeight = view.getResources().getDisplayMetrics().heightPixels;
final int[] screenPos = new int[2];
view.getLocationOnScreen(screenPos);
final int width = view.getWidth();
Toast toast = Toast.makeText(
view.getContext(), view.getContentDescription(), Toast.LENGTH_SHORT);
toast.setGravity(Gravity.BOTTOM | Gravity.END,
screenWidth - screenPos[0] - width / 2,
screenHeight - screenPos[1]);
toast.show();
return true;
}
});
return button;
}
/**
* Builds an {@link ImageButton} from the data in this params. Generated buttons should be
* placed on the bottom bar. The button's tag will be its id.
* @param parent The parent that the inflated {@link ImageButton}.
* @param listener {@link OnClickListener} that should be used with the button.
* @return Parsed list of {@link CustomButtonParams}, which is empty if the input is invalid.
*/
ImageButton buildBottomBarButton(Context context, ViewGroup parent, OnClickListener listener) {
if (mIsOnToolbar) return null;
ImageButton button = (ImageButton) LayoutInflater.from(context)
.inflate(R.layout.custom_tabs_bottombar_item, parent, false);
button.setId(mId);
button.setImageBitmap(mIcon);
button.setContentDescription(mDescription);
if (mPendingIntent == null) {
button.setEnabled(false);
} else {
button.setOnClickListener(listener);
}
button.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
final int screenWidth = view.getResources().getDisplayMetrics().widthPixels;
final int screenHeight = view.getResources().getDisplayMetrics().heightPixels;
final int[] screenPos = new int[2];
view.getLocationOnScreen(screenPos);
final int width = view.getWidth();
Toast toast = Toast.makeText(
view.getContext(), view.getContentDescription(), Toast.LENGTH_SHORT);
toast.setGravity(Gravity.BOTTOM | Gravity.END,
screenWidth - screenPos[0] - width / 2,
screenHeight - screenPos[1]);
toast.show();
return true;
}
});
return button;
}
@Override
protected void onPostExecute(Bitmap result) {
ImageButton button = (ImageButton)findViewById(R.id.openGalleryButton);
View layout = (View)button.getParent();
button.setImageBitmap(result);
button.setEnabled(result != null);
layout.setVisibility(result != null ? View.VISIBLE : View.GONE);
}
/**
* Builds an {@link ImageButton} from the data in this params. Generated buttons should be
* placed on the bottom bar. The button's tag will be its id.
* @param parent The parent that the inflated {@link ImageButton}.
* @param listener {@link OnClickListener} that should be used with the button.
* @return Parsed list of {@link CustomButtonParams}, which is empty if the input is invalid.
*/
ImageButton buildBottomBarButton(Context context, ViewGroup parent, OnClickListener listener) {
if (mIsOnToolbar) return null;
ImageButton button = (ImageButton) LayoutInflater.from(context)
.inflate(R.layout.custom_tabs_bottombar_item, parent, false);
button.setId(mId);
button.setImageBitmap(mIcon);
button.setContentDescription(mDescription);
if (mPendingIntent == null) {
button.setEnabled(false);
} else {
button.setOnClickListener(listener);
}
button.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
final int screenWidth = view.getResources().getDisplayMetrics().widthPixels;
final int screenHeight = view.getResources().getDisplayMetrics().heightPixels;
final int[] screenPos = new int[2];
view.getLocationOnScreen(screenPos);
final int width = view.getWidth();
Toast toast = Toast.makeText(
view.getContext(), view.getContentDescription(), Toast.LENGTH_SHORT);
toast.setGravity(Gravity.BOTTOM | Gravity.END,
screenWidth - screenPos[0] - width / 2,
screenHeight - screenPos[1]);
toast.show();
return true;
}
});
return button;
}
public void updateVideoPreview() {
Bitmap thumb;
thumb = ThumbnailUtils.createVideoThumbnail(videoPath + lastFileName, MediaStore.Video.Thumbnails.MINI_KIND);
ImageButton preview = (ImageButton)findViewById(R.id.preview);
if(thumb == null) {
preview.setVisibility(View.INVISIBLE);
} else {
preview.setVisibility(View.VISIBLE);
preview.setImageBitmap(thumb);
}
}
@Override
public void onMarkerSelected(String icon)
{
iconValue = icon;
ImageButton iconButton = (ImageButton) getView().findViewById(R.id.icon_button);
Androzic application = Androzic.getApplication();
Bitmap b = BitmapFactory.decodeFile(application.markerPath + File.separator + iconValue);
if (b != null)
iconButton.setImageBitmap(b);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
Androzic application = Androzic.getApplication();
View rootView = inflater.inflate(R.layout.act_waypoint_properties, container, false);
tabHost = (TabHost) rootView.findViewById(R.id.tabhost);
tabHost.setup();
tabHost.addTab(tabHost.newTabSpec("main").setIndicator(getString(R.string.primary)).setContent(R.id.properties));
tabHost.addTab(tabHost.newTabSpec("advanced").setIndicator(getString(R.string.advanced)).setContent(R.id.advanced));
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
{
tabHost.getTabWidget().getChildAt(0).getLayoutParams().height = 50;
tabHost.getTabWidget().getChildAt(1).getLayoutParams().height = 50;
}
name = (TextView) rootView.findViewById(R.id.name_text);
description = (TextView) rootView.findViewById(R.id.description_text);
altitude = (TextView) rootView.findViewById(R.id.altitude_text);
proximity = (TextView) rootView.findViewById(R.id.proximity_text);
iconValue = null;
ImageButton icon = (ImageButton) rootView.findViewById(R.id.icon_button);
icon.setImageDrawable(getResources().getDrawable(R.drawable.ic_highlight_remove_white_24dp));
if (waypoint.drawImage)
{
Bitmap b = BitmapFactory.decodeFile(application.markerPath + File.separator + waypoint.marker);
if (b != null)
{
icon.setImageBitmap(b);
iconValue = waypoint.marker;
}
}
icon.setOnClickListener(iconOnClickListener);
ArrayList<String> items = new ArrayList<String>();
for (WaypointSet wptset : application.getWaypointSets())
{
items.add(wptset.name);
}
waypointSet = (Spinner) rootView.findViewById(R.id.set_spinner);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, items);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
waypointSet.setAdapter(adapter);
markercolor = (ColorButton) rootView.findViewById(R.id.markercolor_button);
textcolor = (ColorButton) rootView.findViewById(R.id.textcolor_button);
coordDeg = (ViewGroup) rootView.findViewById(R.id.coord_deg);
coordUtm = (ViewGroup) rootView.findViewById(R.id.coord_utm);
coordMgrs = (ViewGroup) rootView.findViewById(R.id.coord_mgrs);
coordLatDeg = (ViewGroup) rootView.findViewById(R.id.coord_lat_deg);
coordLatMin = (ViewGroup) rootView.findViewById(R.id.coord_lat_min);
coordLatSec = (ViewGroup) rootView.findViewById(R.id.coord_lat_sec);
coordLonDeg = (ViewGroup) rootView.findViewById(R.id.coord_lon_deg);
coordLonMin = (ViewGroup) rootView.findViewById(R.id.coord_lon_min);
coordLonSec = (ViewGroup) rootView.findViewById(R.id.coord_lon_sec);
Spinner coordformat = (Spinner) rootView.findViewById(R.id.coordformat_spinner);
coordformat.setOnItemSelectedListener(this);
coordformat.setSelection(StringFormatter.coordinateFormat);
return rootView;
}