setTextOn ( )源码实例Demo

android.widget.ToggleButton#setTextOn ( )源码实例Demo

下面列出了android.widget.ToggleButton#setTextOn ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: dynamico   文件: ToggleButtonStyler.java
@Override
public View style(View view, JSONObject attributes) throws Exception {
    super.style(view, attributes);

    ToggleButton toggleButton = (ToggleButton) view;

    if(attributes.has("textOn")) {
        toggleButton.setTextOn(attributes.getString("textOn"));
    }

    if(attributes.has("textOff")) {
        toggleButton.setTextOn(attributes.getString("textOff"));
    }

    return toggleButton;
}
 
源代码2 项目: Easer   文件: DayOfWeekSkillViewFragment.java
@NonNull
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.skill_usource__day_of_week, container, false);
    ViewGroup vg = view.findViewById(R.id.plugin__day_of_week_container);
    SimpleDateFormat sdf = new SimpleDateFormat("E", Locale.getDefault());
    Calendar cal = Calendar.getInstance();
    for (int i = 0; i < 7; i++) {
        ToggleButton toggleButton = (ToggleButton) vg.getChildAt(i);
        day_buttons[i] = toggleButton;
        cal.set(Calendar.DAY_OF_WEEK, i + 1);
        String text = sdf.format(cal.getTime());
        toggleButton.setText(text);
        toggleButton.setTextOn(text);
        toggleButton.setTextOff(text);
    }

    return view;
}
 
源代码3 项目: Onosendai   文件: PostToAccountLoaderTask.java
private void configureAccountBtn (final ToggleButton btn, final ServiceRef svc) {
	final String displayName = svc.getUiTitle();
	btn.setTextOn(displayName);
	btn.setTextOff(displayName);

	boolean checked = false;
	if (this.enabledSubAccounts.isEnabled(svc)) {
		checked = true;
	}
	else if (!this.enabledSubAccounts.isServicesPreSpecified()) {
		checked = svc.isDefault();
		if (checked) this.enabledSubAccounts.enable(svc);
	}
	btn.setChecked(checked);

	btn.setOnClickListener(new SubAccountToggleListener(svc, this.enabledSubAccounts));
}
 
源代码4 项目: Faker   文件: Faker.java
/**
 * Fill {@link ToggleButton} on and off text
 * @param view
 * @param component
 */
public void fillOnAndOffWithText(ToggleButton view, FakerTextComponent component) {
    validateNotNullableView(view);
    validateIfIsAToggleButton(view);
    validateNotNullableFakerComponent(component);

    String word = component.randomText();

    view.setTextOff(word);
    view.setTextOn(word);
}
 
源代码5 项目: NoiseCapture   文件: CommentActivity.java
private void addTag(String tagName, int id, ViewGroup column, int color) {
    ToggleButton tagButton = new ToggleButton(this);
    if(color != -1) {
        LinearLayout colorBox = new LinearLayout(this);
        // Convert the dps to pixels, based on density scale
        final int tagPaddingPx = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
                1, getResources().getDisplayMetrics());
        final int tagPaddingPxBottom = (int) TypedValue.applyDimension(TypedValue
                .COMPLEX_UNIT_DIP,
                3, getResources().getDisplayMetrics());
        //use a GradientDrawable with only one color set, to make it a solid color
        colorBox.setBackgroundResource(R.drawable.tag_round_corner);
        GradientDrawable gradientDrawable = (GradientDrawable) colorBox.getBackground();
        gradientDrawable.setColor(color);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams
                .MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
        params.setMargins(tagPaddingPx,tagPaddingPx,tagPaddingPx,tagPaddingPxBottom);
        colorBox.setLayoutParams(params);
        colorBox.addView(tagButton);
        column.addView(colorBox);
    } else {
        column.addView(tagButton);
    }
    tagButton.setTextOff(tagName);
    tagButton.setTextOn(tagName);
    boolean isChecked = checkedTags.contains(id);
    tagButton.setChecked(isChecked);
    if(isChecked) {
        tagButton.setTextColor(selectedColor);
    }
    tagButton.setOnCheckedChangeListener(new TagStateListener(id, checkedTags));
    tagButton.setMinHeight(0);
    tagButton.setMinimumHeight(0);
    tagButton.setTextSize(Dimension.SP, 12);
    tagButton.setEnabled(record == null || record.getUploadId().isEmpty());
    tagButton.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    tagButton.invalidate();
}
 
private void setUpToggle() {
    FrameLayout toggleContainer = findViewById(R.id.toggle_button_container);
    CompoundButton userTypeToggler;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        Switch switchButton = new Switch(this);
        switchButton.setTextOff(Localization.get("toggle.web.user.mode"));
        switchButton.setTextOn(Localization.get("toggle.mobile.user.mode"));
        userTypeToggler = switchButton;
    } else {
        ToggleButton toggleButton = new ToggleButton(this);
        toggleButton.setTextOff(Localization.get("toggle.web.user.mode"));
        toggleButton.setTextOn(Localization.get("toggle.mobile.user.mode"));
        userTypeToggler = toggleButton;
    }

    // Important for this call to come first; we don't want the listener to be invoked on the
    // first auto-setting, just on user-triggered ones
    userTypeToggler.setChecked(inMobileUserAuthMode);
    userTypeToggler.setOnCheckedChangeListener((buttonView, isChecked) -> {
        inMobileUserAuthMode = isChecked;
        errorMessage = null;
        errorMessageBox.setVisibility(View.INVISIBLE);
        ((EditText)findViewById(R.id.edit_password)).setText("");
        setProperAuthView();
    });

    toggleContainer.addView(userTypeToggler);
}
 
@Override
public void createViews(Context context, ViewGroup layout) {
    ToggleButton tb = new ToggleButton(context);
    tb.setText("Vibrate off");
    tb.setTextOff("Vibrate Off");
    tb.setTextOn("Vibrate On");
    PixateFreestyle.setStyleClass(tb, "myToggleButton");

    layout.addView(tb, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

    addView(tb);
}
 
源代码8 项目: SuntimesWidget   文件: AlarmRepeatDialog.java
/**
 *
 */
protected void initViews( final Context context, View dialogContent )
{
    SuntimesUtils.initDisplayStrings(context);

    if (Build.VERSION.SDK_INT >= 14)
    {
        switchRepeat = (SwitchCompat) dialogContent.findViewById(R.id.alarmOption_repeat);
        if (switchRepeat != null)
        {
            switchRepeat.setOnCheckedChangeListener(onRepeatChanged);
            if (colorOverrides[0] != -1) {
                switchRepeat.setThumbTintList(SuntimesUtils.colorStateList(
                        colorOverrides[0],
                        colorOverrides[1],
                        colorOverrides[2],
                        colorOverrides[3]));
                switchRepeat.setTrackTintList(SuntimesUtils.colorStateList(
                        ColorUtils.setAlphaComponent(colorOverrides[0], 85),
                        ColorUtils.setAlphaComponent(colorOverrides[1], 85),
                        ColorUtils.setAlphaComponent(colorOverrides[2], 85),
                        ColorUtils.setAlphaComponent(colorOverrides[3], 85)));  // 33% alpha (85 / 255)
            }
        }

    } else {
        checkRepeat = (CheckBox) dialogContent.findViewById(R.id.alarmOption_repeat);
        if (checkRepeat != null) {
            checkRepeat.setOnCheckedChangeListener(onRepeatChanged);
            CompoundButtonCompat.setButtonTintList(checkRepeat, SuntimesUtils.colorStateList(colorOverrides[0], colorOverrides[1], colorOverrides[2], colorOverrides[3]));
        }
    }

    btnDays = new SparseArray<>();
    btnDays.put(Calendar.SUNDAY, (ToggleButton)dialogContent.findViewById(R.id.alarmOption_repeat_sun));
    btnDays.put(Calendar.MONDAY, (ToggleButton)dialogContent.findViewById(R.id.alarmOption_repeat_mon));
    btnDays.put(Calendar.TUESDAY, (ToggleButton)dialogContent.findViewById(R.id.alarmOption_repeat_tue));
    btnDays.put(Calendar.WEDNESDAY, (ToggleButton)dialogContent.findViewById(R.id.alarmOption_repeat_wed));
    btnDays.put(Calendar.THURSDAY, (ToggleButton)dialogContent.findViewById(R.id.alarmOption_repeat_thu));
    btnDays.put(Calendar.FRIDAY, (ToggleButton)dialogContent.findViewById(R.id.alarmOption_repeat_fri));
    btnDays.put(Calendar.SATURDAY, (ToggleButton)dialogContent.findViewById(R.id.alarmOption_repeat_sat));

    int n = btnDays.size();
    for (int i=0; i<n; i++)
    {
        int day = btnDays.keyAt(i);
        ToggleButton button = btnDays.get(day);
        if (button != null)
        {
            button.setOnCheckedChangeListener(onRepeatDayChanged);
            String dayName = utils.getShortDayString(context, day);
            button.setTextOn(dayName);
            button.setTextOff(dayName);
        }
    }
}
 
源代码9 项目: Multiwii-Remote   文件: MainActivity.java
private void setAuxbtnTxt(ToggleButton mButton, String text) {
	mButton.setText(text);
	mButton.setTextOn(text);
	mButton.setTextOff(text);
}
 
源代码10 项目: bither-android   文件: TabButton.java
private void init() {
    LinearLayout llIcon = new LinearLayout(getContext());
    llIcon.setOrientation(LinearLayout.HORIZONTAL);
    addView(llIcon, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT,
            Gravity.CENTER));
    ivIcon = new ImageView(getContext());
    ivIcon.setPadding(0, 0, 0, UIUtil.dip2pix(0.75f));
    LinearLayout.LayoutParams lpIcon = new LinearLayout.LayoutParams(LayoutParams
            .MATCH_PARENT, LayoutParams.MATCH_PARENT);
    lpIcon.topMargin = UIUtil.dip2pix(3);
    lpIcon.bottomMargin = UIUtil.dip2pix(3);
    lpIcon.gravity = Gravity.CENTER;
    ivIcon.setScaleType(ScaleType.CENTER_INSIDE);
    llIcon.addView(ivIcon, lpIcon);
    tvText = new TextView(getContext());
    tvText.setTextColor(Color.WHITE);
    tvText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
    tvText.setTypeface(null, Typeface.BOLD);
    tvText.setShadowLayer(0.5f, 1, -1, Color.argb(100, 0, 0, 0));
    tvText.setPadding(0, 0, 0, UIUtil.dip2pix(0.75f));
    tvText.setLines(1);
    tvText.setEllipsize(TruncateAt.END);
    llIcon.addView(tvText);
    ivArrowDown = new ImageView(getContext());
    llIcon.addView(ivArrowDown, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    ((LinearLayout.LayoutParams) ivArrowDown.getLayoutParams()).gravity = Gravity
            .CENTER_VERTICAL;
    LinearLayout.LayoutParams lpText = (LinearLayout.LayoutParams) tvText.getLayoutParams();
    lpText.weight = 1;
    lpText.width = 0;
    lpText.gravity = Gravity.CENTER_VERTICAL;
    lpText.leftMargin = UIUtil.dip2pix(-7);
    LayoutParams lpBottom = new LayoutParams(LayoutParams.MATCH_PARENT, UIUtil.dip2pix(2.67f));
    lpBottom.bottomMargin = UIUtil.dip2pix(0.75f);
    lpBottom.gravity = Gravity.BOTTOM;
    tbtnBottom = new ToggleButton(getContext());
    tbtnBottom.setTextOff("");
    tbtnBottom.setTextOn("");
    tbtnBottom.setText("");
    tbtnBottom.setBackgroundResource(R.drawable.tab_bottom_background_selector);
    tbtnBottom.setFocusable(false);
    tbtnBottom.setClickable(false);
    addView(tbtnBottom, lpBottom);

    tvCount = new TextView(getContext());
    tvCount.setTextSize(TypedValue.COMPLEX_UNIT_SP, 9);
    tvCount.setGravity(Gravity.CENTER);
    tvCount.setTextColor(Color.WHITE);
    tvCount.setBackgroundResource(R.drawable.new_message_bg);
    LayoutParams lpCount = new LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT, Gravity.CENTER);
    lpCount.leftMargin = UIUtil.dip2pix(21);
    lpCount.bottomMargin = UIUtil.dip2pix(11);
    addView(tvCount, lpCount);
    tvCount.setVisibility(View.GONE);
    tvText.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
                                                               @Override
                                                               public void onGlobalLayout() {
                                                                   if (!ellipsized) {
                                                                       return;
                                                                   }
                                                                   ellipsized = false;
                                                                   Layout l = tvText.getLayout();
                                                                   if (l != null) {
                                                                       int lines = l.getLineCount();
                                                                       if (lines > 0) {
                                                                           if (l.getEllipsisCount(lines - 1) > 0) {
                                                                               ellipsized = true;
                                                                           }
                                                                       }
                                                                   }
                                                                   updateArrow();
                                                               }
                                                           }
    );
}
 
源代码11 项目: callmeter   文件: LogsFragment.java
/**
 * {@inheritDoc}
 */
@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.logs, container, false);
    tbCall = (ToggleButton) v.findViewById(R.id.calls);
    tbCall.setOnClickListener(this);
    tbSMS = (ToggleButton) v.findViewById(R.id.sms);
    tbSMS.setOnClickListener(this);
    tbMMS = (ToggleButton) v.findViewById(R.id.mms);
    tbMMS.setOnClickListener(this);
    tbData = (ToggleButton) v.findViewById(R.id.data);
    tbData.setOnClickListener(this);
    tbIn = (ToggleButton) v.findViewById(R.id.in);
    tbIn.setOnClickListener(this);
    tbOut = (ToggleButton) v.findViewById(R.id.out);
    tbOut.setOnClickListener(this);
    tbPlan = (ToggleButton) v.findViewById(R.id.plan);
    tbPlan.setOnClickListener(this);
    final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(this
            .getActivity());
    tbCall.setChecked(p.getBoolean(PREF_CALL, true));
    tbSMS.setChecked(p.getBoolean(PREF_SMS, true));
    tbMMS.setChecked(p.getBoolean(PREF_MMS, true));
    tbData.setChecked(p.getBoolean(PREF_DATA, true));
    tbIn.setChecked(p.getBoolean(PREF_IN, true));
    tbOut.setChecked(p.getBoolean(PREF_OUT, true));

    String[] directions = getResources().getStringArray(R.array.direction_calls);
    tbIn.setText(directions[DataProvider.DIRECTION_IN]);
    tbIn.setTextOn(directions[DataProvider.DIRECTION_IN]);
    tbIn.setTextOff(directions[DataProvider.DIRECTION_IN]);
    tbOut.setText(directions[DataProvider.DIRECTION_OUT]);
    tbOut.setTextOn(directions[DataProvider.DIRECTION_OUT]);
    tbOut.setTextOff(directions[DataProvider.DIRECTION_OUT]);

    if (planId >= 0L) {
        setPlanId(planId);
    }

    return v;
}