List of usage examples for android.content.res ColorStateList ColorStateList
public ColorStateList(int[][] states, @ColorInt int[] colors)
From source file:git.egatuts.nxtremotecontroller.activity.ControllerActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.setActiveTheme(super.getPreferenceTheme()); super.setContentView(R.layout.controller_layout); toolbar = (Toolbar) this.findViewById(R.id.toolbar); super.setSupportToolbar(); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override/*from w w w.ja v a2 s . com*/ public void onClick(View v) { ControllerActivity.this.onBackPressed(); } }); /* * We get the device from the extra data of the intent. */ this.device = this.getIntent().getParcelableExtra("device"); /* * We create the final variables we will use in the listeners, etc. */ final ControllerActivity self = this; final GlobalUtils utils = this.getGlobalUtils(); /* * We create the AlertDialog.Builder we will show to ask the user to reconnect with the device. */ this.builder = utils .createAlertDialog(utils.getStringResource(R.string.connecting_reconnect_title), utils.format(R.string.connecting_reconnect_message, this.device.getName())) .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { self.finish(); } }).setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { self.resume(); } }); /* * Now we define the progress dialog we will show while we are connecting with the device. * When the progress dialog has been cancelled it means the connection process has been cancelled. * But on dismiss we have to check if the connection failed or it succeed. */ this.progressDialog = this.getLongProgressDialog(); this.progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { self.aborted = true; utils.showToast(R.string.connecting_aborted); self.connector.closeConnectThread(); self.finish(); } }); /* * Now we declare the handler that will handle (so obviously) the messages * sent by the threads that are in the background connecting with the device. */ this.handler = new Handler() { @Override public void handleMessage(Message msg) { if ((self.connector.getConnectThread() == null || self.aborted) && self.connector.getConnectedThread() == null) { return; } int category = msg.what; int state; int error; if (category == NXTConnector.WHAT_CHANGE_STATE) { progressDialog.show(); state = msg.arg1; error = msg.arg2; if (NXTConnector.isPreparingConnection(state)) { progressDialog.setText(R.string.connecting_preparing_connection); } else if (NXTConnector.isCreatingSocket(state)) { progressDialog.setText(R.string.connecting_creating_socket); } else if (NXTConnector.isConnecting(state)) { progressDialog.setText(R.string.connecting_connecting); } else if (NXTConnector.isConnected(state)) { progressDialog.dismiss(); utils.showToast(R.string.connecting_connected, device.getName()); self.connected(); } } else if (category == NXTConnector.WHAT_ERROR_ENCOUNTERED) { progressDialog.dismiss(); self.connector.closeAllThreads(); error = msg.arg1; state = msg.arg2; boolean notReconnect = false; if (NXTConnector.connectionClosed(state, error)) { utils.showToast(R.string.connecting_connection_closed); notReconnect = true; ControllerActivity.this.finish(); } else if (NXTConnector.connectionLost(state, error)) { utils.showToast(R.string.connecting_connection_lost); if (!self.connector.getBluetoothUtils().isEnabled()) { notReconnect = true; ControllerActivity.this.finish(); } } else if (NXTConnector.connectionSocketFailed(state, error)) { utils.showToast(R.string.connecting_socket_error); } else if (NXTConnector.connectionRequestFailed(state, error)) { utils.showToast(R.string.connecting_request_failed); } else if (NXTConnector.connectionUnexpectedFailed(state, error)) { utils.showToast(R.string.connecting_unexpected_error); } if (!notReconnect) { self.builder.show(); } } } }; /* * Now we create the connector with the device and the handler * which we will use to connect and send messages to the robot. */ this.connector = new NXTConnector(this, this.device, this.handler); /* * We set the title with the device name. */ String title = utils.getStringResource(R.string.controller_window_title); this.setTitle(title + this.device.getName()); /* * We set the colors we will use with the drawables used in the tabs. */ final int underlineColor = utils.getAttribute(R.attr.toolbar_color); final int backgroundColor = utils.getAttribute(R.attr.toolbar_background); final int lightBackgroundColor = GlobalUtils.mixColors(backgroundColor, 0x55FFFFFF); /* * Now we create the drawables used in all the states of the tabs and then we assign * them to a StateListDrawable to add it to the tabs. */ ShapeDrawable.ShaderFactory tabSelectedFactory = new ShapeDrawable.ShaderFactory() { @Override public Shader resize(int width, int height) { return new LinearGradient(0, 0, /* Origin of the background (top left corner) */ 0, height, /* End of the background (bottom left corner) */ new int[] { backgroundColor, backgroundColor, /* The first gradient doesn't change color so it's like a rectangle shape */ underlineColor, underlineColor /* The same for the second one */ }, new float[] { 0, 51f / 55f, /* The first background covers 51dp out of 55dp */ 51f / 55f, 1 /* And the second one takes the rest of the space */ }, Shader.TileMode.REPEAT /* The repeat mode doesn't mind but this would look prettier in case of error */ ); } }; PaintDrawable tabSel = new PaintDrawable(); tabSel.setShape(new RectShape()); tabSel.setShaderFactory(tabSelectedFactory); ShapeDrawable.ShaderFactory tabSelectedAndPressedFactory = new ShapeDrawable.ShaderFactory() { @Override public Shader resize(int width, int height) { return new LinearGradient(0, 0, /* Origin of the background (top left corner) */ 0, height, /* End of the background (bottom left corner) */ new int[] { lightBackgroundColor, lightBackgroundColor, /* The first gradient doesn't change color so it's like a rectangle shape */ underlineColor, underlineColor /* The same for the second one */ }, new float[] { 0, 51f / 55f, /* The first background covers 51dp out of 55dp */ 51f / 55f, 1 /* And the second one takes the rest of the space */ }, Shader.TileMode.REPEAT /* The repeat mode doesn't mind but this would look prettier in case of error */ ); } }; PaintDrawable tabSelAndPress = new PaintDrawable(); tabSelAndPress.setShape(new RectShape()); tabSelAndPress.setShaderFactory(tabSelectedAndPressedFactory); /* * Now we create the states lists for the drawables and the colors. */ StateListDrawable drawableList = new StateListDrawable(); drawableList.addState(new int[] { -android.R.attr.state_selected, android.R.attr.state_pressed }, new ColorDrawable(lightBackgroundColor)); drawableList.addState(new int[] { -android.R.attr.state_selected, android.R.attr.state_pressed, android.R.attr.state_focused }, new ColorDrawable(lightBackgroundColor)); drawableList.addState(new int[] { android.R.attr.state_selected, -android.R.attr.state_pressed }, tabSel); drawableList.addState(new int[] { android.R.attr.state_selected, -android.R.attr.state_pressed, -android.R.attr.state_focused }, tabSel); drawableList.addState(new int[] { android.R.attr.state_selected, android.R.attr.state_pressed }, tabSelAndPress); drawableList.addState(new int[] { android.R.attr.state_selected, android.R.attr.state_pressed, android.R.attr.state_focused }, tabSelAndPress); drawableList.addState(new int[] {}, new ColorDrawable(backgroundColor)); int darkColor = utils.getAttribute(R.attr.toolbar_color); int lightColor = Color.argb(0xAA, Color.red(darkColor), Color.green(darkColor), Color.blue(darkColor)); int[][] states = new int[][] { new int[] { -android.R.attr.state_selected, android.R.attr.state_pressed }, new int[] { -android.R.attr.state_selected, android.R.attr.state_pressed, android.R.attr.state_focused }, new int[] { android.R.attr.state_selected, -android.R.attr.state_pressed }, new int[] { android.R.attr.state_selected, -android.R.attr.state_pressed, -android.R.attr.state_focused }, new int[] { android.R.attr.state_selected, android.R.attr.state_pressed }, new int[] { android.R.attr.state_selected, android.R.attr.state_pressed, android.R.attr.state_focused }, new int[] { -android.R.attr.state_selected, -android.R.attr.state_pressed, -android.R.attr.state_focused }, new int[] {} }; int[] colors = new int[] { lightColor, /* Text color when pressed and not selected */ lightColor, /* Text color when pressed (with focused fallback) */ darkColor, /* Text color when selected and not pressed */ darkColor, /* Text color when selected and not pressed (with focused fallback) */ darkColor, /* Text color when selected and pressed */ darkColor, /* Text color when selected and pressed (with focused fallback) */ lightColor, /* Normal color when not pressed, selected or focused */ lightColor /* Default text color */ }; ColorStateList colorList = new ColorStateList(states, colors); /* * We assign the drawable and the list to the activity instance to be accessible everywhere. */ this.tabSelected = tabSel; this.tabSelectedAndPressed = tabSelAndPress; this.tabDrawableList = drawableList; this.tabColorList = colorList; /* * Now we setup the tab host and add the tabs to the view. */ this.tabHost = (FragmentTabHost) this.findViewById(R.id.tabhost); this.tabHost.setup(this, super.fragmentManager, R.id.tabcontent); this.tabHost.getTabWidget().setDividerDrawable(null); this.addTab(this.createTabView(R.layout.controller_tab, R.string.controller_tab_local_title), R.string.controller_tab_local_spec, LocalControllerFragment.class); this.addTab(this.createTabView(R.layout.controller_tab, R.string.controller_tab_online_title), R.string.controller_tab_online_spec, OnlineControllerFragment.class); }
From source file:com.max.library.view.v7.AppCompatDrawableManager.java
private ColorStateList createButtonColorStateList(Context context, int baseColorAttr) { final int[][] states = new int[4][]; final int[] colors = new int[4]; int i = 0;/* ww w.ja v a 2s . c om*/ final int baseColor = getThemeAttrColor(context, baseColorAttr); final int colorControlHighlight = getThemeAttrColor(context, R.attr.colorControlHighlight); // Disabled state states[i] = ThemeUtils.DISABLED_STATE_SET; colors[i] = getDisabledThemeAttrColor(context, R.attr.colorButtonNormal); i++; states[i] = ThemeUtils.PRESSED_STATE_SET; colors[i] = ColorUtils.compositeColors(colorControlHighlight, baseColor); i++; states[i] = ThemeUtils.FOCUSED_STATE_SET; colors[i] = ColorUtils.compositeColors(colorControlHighlight, baseColor); i++; // Default enabled state states[i] = ThemeUtils.EMPTY_STATE_SET; colors[i] = baseColor; i++; return new ColorStateList(states, colors); }
From source file:com.shopify.buy.ui.ProductDetailsFragmentView.java
private void initializeCheckoutButton() { checkoutButtonContainer = (ViewGroup) findViewById(R.id.checkout_button_container); checkoutButtonContainer.setBackgroundColor(theme.getAccentColor()); Button checkoutButton = (Button) findViewById(R.id.checkout_button); int disabledTextAlpha = 64; // 0.25 * 255 checkoutButton/*from ww w. j a v a 2 s. c o m*/ .setTextColor( new ColorStateList( new int[][] { new int[] { -android.R.attr.state_enabled }, new int[] { android.R.attr.state_enabled } }, new int[] { ColorUtils.setAlphaComponent(theme.getCheckoutLabelColor(getResources()), disabledTextAlpha), theme.getCheckoutLabelColor(getResources()), })); }
From source file:com.max.library.view.v7.AppCompatDrawableManager.java
private ColorStateList createSpinnerColorStateList(Context context) { final int[][] states = new int[3][]; final int[] colors = new int[3]; int i = 0;// w w w . j a v a 2 s . c om // Disabled state states[i] = ThemeUtils.DISABLED_STATE_SET; colors[i] = getDisabledThemeAttrColor(context, R.attr.colorControlNormal); i++; states[i] = ThemeUtils.NOT_PRESSED_OR_FOCUSED_STATE_SET; colors[i] = getThemeAttrColor(context, R.attr.colorControlNormal); i++; states[i] = ThemeUtils.EMPTY_STATE_SET; colors[i] = getThemeAttrColor(context, R.attr.colorControlActivated); i++; return new ColorStateList(states, colors); }
From source file:com.max.library.view.v7.AppCompatDrawableManager.java
private ColorStateList createSeekbarThumbColorStateList(Context context) { final int[][] states = new int[2][]; final int[] colors = new int[2]; int i = 0;// w w w.ja va 2 s. c o m // Disabled state states[i] = ThemeUtils.DISABLED_STATE_SET; colors[i] = getDisabledThemeAttrColor(context, R.attr.colorControlActivated); i++; states[i] = ThemeUtils.EMPTY_STATE_SET; colors[i] = getThemeAttrColor(context, R.attr.colorControlActivated); i++; return new ColorStateList(states, colors); }
From source file:com.anysoftkeyboard.keyboards.views.AnyKeyboardViewBase.java
protected boolean setValueFromTheme(TypedArray remoteTypedArray, final int[] padding, final int localAttrId, final int remoteTypedArrayIndex) { try {//from w w w . j a v a 2s .c om switch (localAttrId) { case android.R.attr.background: Drawable keyboardBackground = remoteTypedArray.getDrawable(remoteTypedArrayIndex); if (keyboardBackground == null) return false; CompatUtils.setViewBackgroundDrawable(this, keyboardBackground); break; case android.R.attr.paddingLeft: padding[0] = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, -1); if (padding[0] == -1) return false; break; case android.R.attr.paddingTop: padding[1] = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, -1); if (padding[1] == -1) return false; break; case android.R.attr.paddingRight: padding[2] = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, -1); if (padding[2] == -1) return false; break; case android.R.attr.paddingBottom: padding[3] = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, -1); if (padding[3] == -1) return false; break; case R.attr.keyBackground: mKeyBackground = remoteTypedArray.getDrawable(remoteTypedArrayIndex); if (mKeyBackground == null) return false; break; case R.attr.keyHysteresisDistance: mKeyHysteresisDistance = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, -1); if (mKeyHysteresisDistance == -1) return false; break; case R.attr.verticalCorrection: mOriginalVerticalCorrection = mVerticalCorrection = remoteTypedArray .getDimensionPixelOffset(remoteTypedArrayIndex, -1); if (mOriginalVerticalCorrection == -1) return false; break; case R.attr.keyTextSize: mKeyTextSize = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, -1); if (mKeyTextSize == -1) return false; // you might ask yourself "why did Menny sqrt root the factor?" // I'll tell you; the factor is mostly for the height, not the // font size, // but I also factorize the font size because I want the text to // be a little like // the key size. // the whole factor maybe too much, so I ease that a bit. if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) mKeyTextSize = (float) (mKeyTextSize * Math.sqrt(AnyApplication.getConfig().getKeysHeightFactorInLandscape())); else mKeyTextSize = (float) (mKeyTextSize * Math.sqrt(AnyApplication.getConfig().getKeysHeightFactorInPortrait())); Logger.d(TAG, "AnySoftKeyboardTheme_keyTextSize " + mKeyTextSize); break; case R.attr.keyTextColor: mKeyTextColor = remoteTypedArray.getColorStateList(remoteTypedArrayIndex); if (mKeyTextColor == null) { mKeyTextColor = new ColorStateList(new int[][] { { 0 } }, new int[] { remoteTypedArray.getColor(remoteTypedArrayIndex, 0xFF000000) }); } break; case R.attr.labelTextSize: mLabelTextSize = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, -1); if (mLabelTextSize == -1) return false; if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) mLabelTextSize = mLabelTextSize * AnyApplication.getConfig().getKeysHeightFactorInLandscape(); else mLabelTextSize = mLabelTextSize * AnyApplication.getConfig().getKeysHeightFactorInPortrait(); break; case R.attr.keyboardNameTextSize: mKeyboardNameTextSize = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, -1); if (mKeyboardNameTextSize == -1) return false; if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) mKeyboardNameTextSize = mKeyboardNameTextSize * AnyApplication.getConfig().getKeysHeightFactorInLandscape(); else mKeyboardNameTextSize = mKeyboardNameTextSize * AnyApplication.getConfig().getKeysHeightFactorInPortrait(); break; case R.attr.keyboardNameTextColor: mKeyboardNameTextColor = remoteTypedArray.getColor(remoteTypedArrayIndex, Color.WHITE); break; case R.attr.shadowColor: mShadowColor = remoteTypedArray.getColor(remoteTypedArrayIndex, 0); break; case R.attr.shadowRadius: mShadowRadius = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, 0); break; case R.attr.shadowOffsetX: mShadowOffsetX = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, 0); break; case R.attr.shadowOffsetY: mShadowOffsetY = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, 0); break; case R.attr.backgroundDimAmount: mBackgroundDimAmount = remoteTypedArray.getFloat(remoteTypedArrayIndex, -1f); if (mBackgroundDimAmount == -1f) return false; break; case R.attr.keyPreviewBackground: Drawable keyPreviewBackground = remoteTypedArray.getDrawable(remoteTypedArrayIndex); if (keyPreviewBackground == null) return false; mPreviewPopupTheme.setPreviewKeyBackground(keyPreviewBackground); break; case R.attr.keyPreviewTextColor: mPreviewPopupTheme.setPreviewKeyTextColor(remoteTypedArray.getColor(remoteTypedArrayIndex, 0xFFF)); break; case R.attr.keyPreviewTextSize: mPreviewPopupTheme .setPreviewKeyTextSize(remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, 0)); break; case R.attr.keyPreviewLabelTextSize: mPreviewPopupTheme .setPreviewLabelTextSize(remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, 0)); break; case R.attr.keyPreviewOffset: mPreviewPopupTheme .setVerticalOffset(remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, 0)); break; case R.attr.previewAnimationType: int previewAnimationType = remoteTypedArray.getInteger(remoteTypedArrayIndex, -1); if (previewAnimationType == -1) return false; mPreviewPopupTheme.setPreviewAnimationType(previewAnimationType); break; case R.attr.keyTextStyle: int textStyle = remoteTypedArray.getInt(remoteTypedArrayIndex, 0); switch (textStyle) { case 0: mKeyTextStyle = Typeface.DEFAULT; break; case 1: mKeyTextStyle = Typeface.DEFAULT_BOLD; break; case 2: mKeyTextStyle = Typeface.defaultFromStyle(Typeface.ITALIC); break; default: mKeyTextStyle = Typeface.defaultFromStyle(textStyle); break; } mPreviewPopupTheme.setKeyStyle(mKeyTextStyle); break; case R.attr.keyHorizontalGap: float themeHorizontalKeyGap = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, -1); if (themeHorizontalKeyGap == -1) return false; mKeyboardDimens.setHorizontalKeyGap(themeHorizontalKeyGap); break; case R.attr.keyVerticalGap: float themeVerticalRowGap = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, -1); if (themeVerticalRowGap == -1) return false; mKeyboardDimens.setVerticalRowGap(themeVerticalRowGap); break; case R.attr.keyNormalHeight: int themeNormalKeyHeight = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, -1); if (themeNormalKeyHeight == -1) return false; mKeyboardDimens.setNormalKeyHeight(themeNormalKeyHeight); break; case R.attr.keyLargeHeight: int themeLargeKeyHeight = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, -1); if (themeLargeKeyHeight == -1) return false; mKeyboardDimens.setLargeKeyHeight(themeLargeKeyHeight); break; case R.attr.keySmallHeight: int themeSmallKeyHeight = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, -1); if (themeSmallKeyHeight == -1) return false; mKeyboardDimens.setSmallKeyHeight(themeSmallKeyHeight); break; case R.attr.hintTextSize: mHintTextSize = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, -1); if (mHintTextSize == -1) return false; if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) mHintTextSize = mHintTextSize * AnyApplication.getConfig().getKeysHeightFactorInLandscape(); else mHintTextSize = mHintTextSize * AnyApplication.getConfig().getKeysHeightFactorInPortrait(); break; case R.attr.hintTextColor: mHintTextColor = remoteTypedArray.getColorStateList(remoteTypedArrayIndex); if (mHintTextColor == null) { mHintTextColor = new ColorStateList(new int[][] { { 0 } }, new int[] { remoteTypedArray.getColor(remoteTypedArrayIndex, 0xFF000000) }); } break; case R.attr.hintLabelVAlign: mHintLabelVAlign = remoteTypedArray.getInt(remoteTypedArrayIndex, Gravity.BOTTOM); break; case R.attr.hintLabelAlign: mHintLabelAlign = remoteTypedArray.getInt(remoteTypedArrayIndex, Gravity.RIGHT); break; case R.attr.hintOverflowLabel: mHintOverflowLabel = remoteTypedArray.getString(remoteTypedArrayIndex); break; } return true; } catch (Exception e) { // on API changes, so the incompatible themes wont crash me.. e.printStackTrace(); return false; } }
From source file:io.github.yavski.fabspeeddial.FabSpeedDial.java
private ColorStateList getColorStateList(int colorRes) { int[][] states = new int[][] { new int[] { android.R.attr.state_enabled }, // enabled new int[] { -android.R.attr.state_enabled }, // disabled new int[] { -android.R.attr.state_checked }, // unchecked new int[] { android.R.attr.state_pressed } // pressed };//from w w w.ja v a2 s . c o m int color = ContextCompat.getColor(getContext(), colorRes); int[] colors = new int[] { color, color, color, color }; return new ColorStateList(states, colors); }
From source file:android.support.v7ox.widget.AppCompatDrawableManager.java
private ColorStateList createDefaultColorStateList(Context context) { /**/*w w w.ja va 2 s . co m*/ * Generate the default color state list which uses the colorControl attributes. * Order is important here. The default enabled state needs to go at the bottom. */ final int colorControlNormal = ThemeUtils.getThemeAttrColor(context, R.attr.colorControlNormal_ox); final int colorControlActivated = ThemeUtils.getThemeAttrColor(context, R.attr.colorControlActivated_ox); final int[][] states = new int[7][]; final int[] colors = new int[7]; int i = 0; // Disabled state states[i] = ThemeUtils.DISABLED_STATE_SET; colors[i] = ThemeUtils.getDisabledThemeAttrColor(context, R.attr.colorControlNormal_ox); i++; states[i] = ThemeUtils.FOCUSED_STATE_SET; colors[i] = colorControlActivated; i++; states[i] = ThemeUtils.ACTIVATED_STATE_SET; colors[i] = colorControlActivated; i++; states[i] = ThemeUtils.PRESSED_STATE_SET; colors[i] = colorControlActivated; i++; states[i] = ThemeUtils.CHECKED_STATE_SET; colors[i] = colorControlActivated; i++; states[i] = ThemeUtils.SELECTED_STATE_SET; colors[i] = colorControlActivated; i++; // Default enabled state states[i] = ThemeUtils.EMPTY_STATE_SET; colors[i] = colorControlNormal; i++; return new ColorStateList(states, colors); }
From source file:com.gh4a.BaseActivity.java
private ColorStateList createDefaultNavigationColorStateList(int baseColorThemeAttr) { TypedValue value = new TypedValue(); if (!getTheme().resolveAttribute(baseColorThemeAttr, value, true)) { return null; }// w w w . j ava 2s . co m ColorStateList baseColor = ContextCompat.getColorStateList(this, value.resourceId); if (!getTheme().resolveAttribute(android.support.design.R.attr.colorAccent, value, true)) { return null; } int colorAccent = value.data; int defaultColor = baseColor.getDefaultColor(); final int[] disabledStateSet = { -android.R.attr.state_enabled }; final int[] checkedStateSet = { android.R.attr.state_checked }; final int[][] states = { disabledStateSet, checkedStateSet, { 0 } }; final int[] colors = { baseColor.getColorForState(disabledStateSet, defaultColor), colorAccent, defaultColor }; return new ColorStateList(states, colors); }
From source file:android.support.v7ox.widget.AppCompatDrawableManager.java
private ColorStateList createCheckableButtonColorStateList(Context context) { final int[][] states = new int[3][]; final int[] colors = new int[3]; int i = 0;/* www . j a va 2 s .c o m*/ // Disabled state states[i] = ThemeUtils.DISABLED_STATE_SET; colors[i] = ThemeUtils.getDisabledThemeAttrColor(context, R.attr.colorControlNormal_ox); i++; states[i] = ThemeUtils.CHECKED_STATE_SET; colors[i] = ThemeUtils.getThemeAttrColor(context, R.attr.colorControlActivated_ox); i++; // Default enabled state states[i] = ThemeUtils.EMPTY_STATE_SET; colors[i] = ThemeUtils.getThemeAttrColor(context, R.attr.colorControlNormal_ox); i++; return new ColorStateList(states, colors); }