Java Code Examples for android.widget.ToggleButton#setText()

The following examples show how to use android.widget.ToggleButton#setText() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DayOfWeekSkillViewFragment.java    From Easer with GNU General Public License v3.0 6 votes vote down vote up
@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;
}
 
Example 2
Source File: ToggleButtonViewSample.java    From pixate-freestyle-android with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 3
Source File: MainActivity.java    From Multiwii-Remote with Apache License 2.0 4 votes vote down vote up
private void setAuxbtnTxt(ToggleButton mButton, String text) {
	mButton.setText(text);
	mButton.setTextOn(text);
	mButton.setTextOff(text);
}
 
Example 4
Source File: TabButton.java    From bither-android with Apache License 2.0 4 votes vote down vote up
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();
                                                               }
                                                           }
    );
}
 
Example 5
Source File: LogsFragment.java    From callmeter with GNU General Public License v3.0 4 votes vote down vote up
/**
 * {@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;
}