下面列出了android.widget.ToggleButton#setText ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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;
}
@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);
}
private void setAuxbtnTxt(ToggleButton mButton, String text) {
mButton.setText(text);
mButton.setTextOn(text);
mButton.setTextOff(text);
}
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();
}
}
);
}
/**
* {@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;
}