Skip to content

Commit 787f269

Browse files
adampAndroid (Google) Code Review
authored andcommitted
Merge "Public API for android.widget.Switch properties"
2 parents 3426467 + 6c86e1b commit 787f269

File tree

2 files changed

+139
-0
lines changed

2 files changed

+139
-0
lines changed

api/current.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27518,14 +27518,24 @@ package android.widget {
2751827518
ctor public Switch(android.content.Context);
2751927519
ctor public Switch(android.content.Context, android.util.AttributeSet);
2752027520
ctor public Switch(android.content.Context, android.util.AttributeSet, int);
27521+
method public int getSwitchMinWidth();
27522+
method public int getSwitchPadding();
2752127523
method public java.lang.CharSequence getTextOff();
2752227524
method public java.lang.CharSequence getTextOn();
27525+
method public android.graphics.drawable.Drawable getThumbDrawable();
27526+
method public int getThumbTextPadding();
27527+
method public android.graphics.drawable.Drawable getTrackDrawable();
2752327528
method public void onMeasure(int, int);
27529+
method public void setSwitchMinWidth(int);
27530+
method public void setSwitchPadding(int);
2752427531
method public void setSwitchTextAppearance(android.content.Context, int);
2752527532
method public void setSwitchTypeface(android.graphics.Typeface, int);
2752627533
method public void setSwitchTypeface(android.graphics.Typeface);
2752727534
method public void setTextOff(java.lang.CharSequence);
2752827535
method public void setTextOn(java.lang.CharSequence);
27536+
method public void setThumbDrawable(android.graphics.drawable.Drawable);
27537+
method public void setThumbTextPadding(int);
27538+
method public void setTrackDrawable(android.graphics.drawable.Drawable);
2752927539
}
2753027540

2753127541
public class TabHost extends android.widget.FrameLayout implements android.view.ViewTreeObserver.OnTouchModeChangeListener {

core/java/android/widget/Switch.java

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ public Switch(Context context, AttributeSet attrs, int defStyle) {
169169
/**
170170
* Sets the switch text color, size, style, hint color, and highlight color
171171
* from the specified TextAppearance resource.
172+
*
173+
* @attr ref android.R.styleable#Switch_switchTextAppearance
172174
*/
173175
public void setSwitchTextAppearance(Context context, int resid) {
174176
TypedArray appearance =
@@ -273,15 +275,138 @@ public void setSwitchTypeface(Typeface tf) {
273275
}
274276
}
275277

278+
/**
279+
* Set the amount of horizontal padding between the switch and the associated text.
280+
*
281+
* @param pixels Amount of padding in pixels
282+
*
283+
* @attr ref android.R.styleable#Switch_switchPadding
284+
*/
285+
public void setSwitchPadding(int pixels) {
286+
mSwitchPadding = pixels;
287+
requestLayout();
288+
}
289+
290+
/**
291+
* Get the amount of horizontal padding between the switch and the associated text.
292+
*
293+
* @return Amount of padding in pixels
294+
*
295+
* @attr ref android.R.styleable#Switch_switchPadding
296+
*/
297+
public int getSwitchPadding() {
298+
return mSwitchPadding;
299+
}
300+
301+
/**
302+
* Set the minimum width of the switch in pixels. The switch's width will be the maximum
303+
* of this value and its measured width as determined by the switch drawables and text used.
304+
*
305+
* @param pixels Minimum width of the switch in pixels
306+
*
307+
* @attr ref android.R.styleable#Switch_switchMinWidth
308+
*/
309+
public void setSwitchMinWidth(int pixels) {
310+
mSwitchMinWidth = pixels;
311+
requestLayout();
312+
}
313+
314+
/**
315+
* Get the minimum width of the switch in pixels. The switch's width will be the maximum
316+
* of this value and its measured width as determined by the switch drawables and text used.
317+
*
318+
* @return Minimum width of the switch in pixels
319+
*
320+
* @attr ref android.R.styleable#Switch_switchMinWidth
321+
*/
322+
public int getSwitchMinWidth() {
323+
return mSwitchMinWidth;
324+
}
325+
326+
/**
327+
* Set the horizontal padding around the text drawn on the switch itself.
328+
*
329+
* @param pixels Horizontal padding for switch thumb text in pixels
330+
*
331+
* @attr ref android.R.styleable#Switch_thumbTextPadding
332+
*/
333+
public void setThumbTextPadding(int pixels) {
334+
mThumbTextPadding = pixels;
335+
requestLayout();
336+
}
337+
338+
/**
339+
* Get the horizontal padding around the text drawn on the switch itself.
340+
*
341+
* @return Horizontal padding for switch thumb text in pixels
342+
*
343+
* @attr ref android.R.styleable#Switch_thumbTextPadding
344+
*/
345+
public int getThumbTextPadding() {
346+
return mThumbTextPadding;
347+
}
348+
349+
/**
350+
* Set the drawable used for the track that the switch slides within.
351+
*
352+
* @param track Track drawable
353+
*
354+
* @attr ref android.R.styleable#Switch_track
355+
*/
356+
public void setTrackDrawable(Drawable track) {
357+
mTrackDrawable = track;
358+
requestLayout();
359+
}
360+
361+
/**
362+
* Get the drawable used for the track that the switch slides within.
363+
*
364+
* @return Track drawable
365+
*
366+
* @attr ref android.R.styleable#Switch_track
367+
*/
368+
public Drawable getTrackDrawable() {
369+
return mTrackDrawable;
370+
}
371+
372+
/**
373+
* Set the drawable used for the switch "thumb" - the piece that the user
374+
* can physically touch and drag along the track.
375+
*
376+
* @param thumb Thumb drawable
377+
*
378+
* @attr ref android.R.styleable#Switch_thumb
379+
*/
380+
public void setThumbDrawable(Drawable thumb) {
381+
mThumbDrawable = thumb;
382+
requestLayout();
383+
}
384+
385+
/**
386+
* Get the drawable used for the switch "thumb" - the piece that the user
387+
* can physically touch and drag along the track.
388+
*
389+
* @return Thumb drawable
390+
*
391+
* @attr ref android.R.styleable#Switch_thumb
392+
*/
393+
public Drawable getThumbDrawable() {
394+
return mThumbDrawable;
395+
}
396+
276397
/**
277398
* Returns the text displayed when the button is in the checked state.
399+
*
400+
* @attr ref android.R.styleable#Switch_textOn
278401
*/
279402
public CharSequence getTextOn() {
280403
return mTextOn;
281404
}
282405

283406
/**
284407
* Sets the text displayed when the button is in the checked state.
408+
*
409+
* @attr ref android.R.styleable#Switch_textOn
285410
*/
286411
public void setTextOn(CharSequence textOn) {
287412
mTextOn = textOn;
@@ -290,13 +415,17 @@ public void setTextOn(CharSequence textOn) {
290415

291416
/**
292417
* Returns the text displayed when the button is not in the checked state.
418+
*
419+
* @attr ref android.R.styleable#Switch_textOff
293420
*/
294421
public CharSequence getTextOff() {
295422
return mTextOff;
296423
}
297424

298425
/**
299426
* Sets the text displayed when the button is not in the checked state.
427+
*
428+
* @attr ref android.R.styleable#Switch_textOff
300429
*/
301430
public void setTextOff(CharSequence textOff) {
302431
mTextOff = textOff;

0 commit comments

Comments
 (0)