Skip to content

Instantly share code, notes, and snippets.

@wbspry
Created September 12, 2016 01:40
Show Gist options
  • Save wbspry/4cc2179f86d357d75c1c4fce15cff58b to your computer and use it in GitHub Desktop.
Save wbspry/4cc2179f86d357d75c1c4fce15cff58b to your computer and use it in GitHub Desktop.
public class MultiLineSwitchPreference extends SwitchPreference {
public MultiLineSwitchPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
public MultiLineSwitchPreference(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public MultiLineSwitchPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MultiLineSwitchPreference(Context context) {
super(context);
}
protected void onBindView(View view){
super.onBindView(view);
adjustViews(view);
}
protected void adjustViews( View view){
if ( view instanceof ViewGroup){
ViewGroup group=(ViewGroup)view;
for ( int index = 0; index < group.getChildCount(); index++)
adjustViews(group.getChildAt(index));
} else if (view instanceof TextView){
// adjust your textViews here
TextView t = (TextView)view;
t.setSingleLine(false);
t.setEllipsize(null);
}
}
}
@wbspry
Copy link
Author

wbspry commented Sep 12, 2016

SwitchPreferenceを拡張してTitleを複数行表示できるようにしたもの。
Androidのバグで拡張するとスイッチのアニメーションが効かなくなる。
https://code.google.com/p/android/issues/detail?id=212142)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment