private void init() { mFm = getSupportFragmentManager(); mNavigationBar = (RadioGroup) findViewById(R.id.navigation); int size = (int) getResources().getDimension(R.dimen.navigation_top_icon_size); for (int i = 0, count = mNavigationBar.getChildCount(); i < count; i++) { RadioButton rb = (RadioButton) mNavigationBar.getChildAt(i); Drawable topIcon = getResources().getDrawable(R.drawable.selector_navigation_bg); topIcon.setBounds(0, 0, size, size); rb.setCompoundDrawables(null, topIcon, null, null); rb.setId(i); } mNavigationBar.setOnCheckedChangeListener(this); ((RadioButton) mNavigationBar.getChildAt(0)).setChecked(true); }
@Override public void setCompoundDrawables(Drawable left, Drawable top, Drawable right, Drawable bottom) { setDrawableBounds(left, drawableLeftWidth, drawableLeftHeight, drawableWidth, drawableHeight); setDrawableBounds(top, drawableTopWidth,drawableTopHeight, drawableWidth,drawableHeight); setDrawableBounds(right, drawableRightWidth, drawableRightHeight,drawableWidth,drawableHeight); setDrawableBounds(bottom, drawableBottomWidth, drawableBottomHeight, drawableWidth,drawableHeight); super.setCompoundDrawables(left, top, right, bottom); } }
public void onCreate(RadioButton[] rb) { for (int i = 0; i < rb.length; i++) { final String text = ctx.getString(R.string.dialog_function_selection) + " " + Integer.toString(i + 1) + ":"; rb[i].setText(text); final Paint p = functions.get(i).getLineParameters().getPaint(); final int textWidth = (int) rb[i].getPaint().measureText(text); rb[i].setCompoundDrawables(null, null, new LineDrawable(p, textWidth, (int) (p.getStrokeWidth() + 4)), null); rb[i].setCompoundDrawablePadding(ctx.getResources().getDimensionPixelSize( R.dimen.dialog_content_padding)); } }
private void refreshTrezorsList() { ImmutableList<InitializedTrezor> trezors = gct.getCommonDb().getTrezors(); if (radioGroupTrezors.getChildCount() > trezors.size()) { radioGroupTrezors.removeViews(trezors.size(), radioGroupTrezors.getChildCount() - trezors.size()); } LayoutInflater inflater = LayoutInflater.from(radioGroupTrezors.getContext()); for (int i = radioGroupTrezors.getChildCount(); i < trezors.size(); i++) { RadioButton btn = (RadioButton)inflater.inflate(R.layout.nav_drawer_trezor_radiobutton, radioGroupTrezors, false); btn.setCompoundDrawables(createNavDrawerButtonIcon(R.drawable.ic_trezor), null, null, null); btn.setOnClickListener(onTrezorClickListener); radioGroupTrezors.addView(btn); } for (int i = 0; i < trezors.size(); i++) { InitializedTrezor t = trezors.get(i); RadioButton btn = (RadioButton)radioGroupTrezors.getChildAt(i); btn.setText(TextUtils.isEmpty(t.getFeatures().getLabel()) ? btn.getContext().getString(R.string.init_trezor_device_label_default) : t.getFeatures().getLabel()); int id = getTrezorButtonId(t.getFeatures().getDeviceId()); btn.setId(id); } refreshCurrentSelectedTrezor(gct.getCommonDb().getLastSelectedDeviceId()); radioGroupTrezors.setVisibility(trezors.isEmpty() ? View.GONE : View.VISIBLE); dividerTrezors.setVisibility(trezors.isEmpty() ? View.GONE : View.VISIBLE); }