List of usage examples for android.graphics.drawable StateListDrawable setState
public boolean setState(@NonNull final int[] stateSet)
From source file:com.landenlabs.all_devtool.IconBaseFragment.java
/** * Show a 'StateListDrawable' information * * @param imageView// ww w . j a v a 2 s.c o m * @param row1 * @param row2 * @param stateListDrawable * @param state * @param desc * @param stateIcons */ private void showStateIcon(final ImageView imageView, TableRow row1, TableRow row2, StateListDrawable stateListDrawable, int state, String desc, Set<Drawable> stateIcons) { stateListDrawable.setState(new int[] { state }); Drawable stateD = stateListDrawable.getCurrent(); if (stateD != null && !stateIcons.contains(stateD)) { stateIcons.add(stateD); ImageButton stateImageView = new ImageButton(imageView.getContext()); Drawable[] drawables = new Drawable[] { stateD, getResources().getDrawable(R.drawable.button_border_sel) }; LayerDrawable layerDrawable = new LayerDrawable(drawables); stateImageView.setImageDrawable(layerDrawable); // stateImageView.setBackgroundResource(R.drawable.button_border_sel); stateImageView.setPadding(10, 10, 10, 10); stateImageView.setMinimumHeight(8); stateImageView.setMinimumWidth(8); stateImageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { imageView.setImageDrawable(((ImageView) v).getDrawable()); } }); TextView stateTextView = new TextView(imageView.getContext()); stateTextView.setText(desc); stateTextView.setTextSize(12); stateTextView.setGravity(Gravity.CENTER); row1.addView(stateTextView); row2.addView(stateImageView); } }
From source file:com.winneredge.stockly.wcommons.floatingactionwidget.FloatingActionButton.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) void onActionDown() { if (mBackgroundDrawable instanceof StateListDrawable) { StateListDrawable drawable = (StateListDrawable) mBackgroundDrawable; drawable.setState(new int[] { android.R.attr.state_enabled, android.R.attr.state_pressed }); } else if (Util.hasLollipop()) { RippleDrawable ripple = (RippleDrawable) mBackgroundDrawable; ripple.setState(new int[] { android.R.attr.state_enabled, android.R.attr.state_pressed }); ripple.setHotspot(calculateCenterX(), calculateCenterY()); ripple.setVisible(true, true);//from ww w . j av a 2s. c o m } }
From source file:com.winneredge.stockly.wcommons.floatingactionwidget.FloatingActionButton.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) void onActionUp() { if (mBackgroundDrawable instanceof StateListDrawable) { StateListDrawable drawable = (StateListDrawable) mBackgroundDrawable; drawable.setState(new int[] { android.R.attr.state_enabled }); } else if (Util.hasLollipop()) { RippleDrawable ripple = (RippleDrawable) mBackgroundDrawable; ripple.setState(new int[] { android.R.attr.state_enabled }); ripple.setHotspot(calculateCenterX(), calculateCenterY()); ripple.setVisible(true, true);/*from w w w . j a v a 2 s .c o m*/ } }