use of android.support.v7.widget.SwitchCompat in project recyclerview-animators by wasabeef.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.btn_animator_sample).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this, AnimatorSampleActivity.class);
i.putExtra("GRID", enabledGrid);
startActivity(i);
}
});
findViewById(R.id.btn_adapter_sample).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this, AdapterSampleActivity.class);
i.putExtra("GRID", enabledGrid);
startActivity(i);
}
});
((SwitchCompat) findViewById(R.id.grid)).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
enabledGrid = isChecked;
}
});
}
use of android.support.v7.widget.SwitchCompat in project LookLook by xinghongfei.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_layout);
ButterKnife.bind(this);
setSupportActionBar(toolbar);
IMainPresenter = new MainPresenterImpl(this, this);
IMainPresenter.getBackground();
toolbar.setOnMenuItemClickListener(onMenuItemClick);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
animateToolbar();
}
addfragmentsAndTitle();
// setStatusColor();
drawer.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
if (savedInstanceState == null) {
nevigationId = SharePreferenceUtil.getNevigationItem(this);
if (nevigationId != -1) {
currentMenuItem = navView.getMenu().findItem(nevigationId);
}
if (currentMenuItem == null) {
currentMenuItem = navView.getMenu().findItem(R.id.zhihuitem);
}
if (currentMenuItem != null) {
currentMenuItem.setChecked(true);
// TODO: 16/8/17 add a fragment and set toolbar title
Fragment fragment = getFragmentById(currentMenuItem.getItemId());
String title = mTitleArryMap.get((Integer) currentMenuItem.getItemId());
if (fragment != null) {
switchFragment(fragment, title);
}
}
} else {
if (currentMenuItem != null) {
Fragment fragment = getFragmentById(currentMenuItem.getItemId());
String title = mTitleArryMap.get((Integer) currentMenuItem.getItemId());
if (fragment != null) {
switchFragment(fragment, title);
}
} else {
switchFragment(new ZhihuFragment(), " ");
currentMenuItem = navView.getMenu().findItem(R.id.zhihuitem);
}
}
navView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(MenuItem item) {
if (currentMenuItem != item && currentMenuItem != null) {
currentMenuItem.setChecked(false);
int id = item.getItemId();
SharePreferenceUtil.putNevigationItem(MainActivity.this, id);
currentMenuItem = item;
currentMenuItem.setChecked(true);
switchFragment(getFragmentById(currentMenuItem.getItemId()), mTitleArryMap.get(currentMenuItem.getItemId()));
}
drawer.closeDrawer(GravityCompat.END, true);
return true;
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
drawer.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
@Override
public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
// inset the toolbar down by the status bar height
ViewGroup.MarginLayoutParams lpToolbar = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams();
lpToolbar.topMargin += insets.getSystemWindowInsetTop();
lpToolbar.rightMargin += insets.getSystemWindowInsetRight();
toolbar.setLayoutParams(lpToolbar);
// inset the grid top by statusbar+toolbar & the bottom by the navbar (don't clip)
mFragmentContainer.setPadding(mFragmentContainer.getPaddingLeft(), insets.getSystemWindowInsetTop() + ViewUtils.getActionBarSize(MainActivity.this), // landscape
mFragmentContainer.getPaddingRight() + insets.getSystemWindowInsetRight(), mFragmentContainer.getPaddingBottom() + insets.getSystemWindowInsetBottom());
// we place a background behind the status bar to combine with it's semi-transparent
// color to get the desired appearance. Set it's height to the status bar height
View statusBarBackground = findViewById(R.id.status_bar_background);
FrameLayout.LayoutParams lpStatus = (FrameLayout.LayoutParams) statusBarBackground.getLayoutParams();
lpStatus.height = insets.getSystemWindowInsetTop();
statusBarBackground.setLayoutParams(lpStatus);
// inset the filters list for the status bar / navbar
// need to set the padding end for landscape case
// clear this listener so insets aren't re-applied
drawer.setOnApplyWindowInsetsListener(null);
return insets.consumeSystemWindowInsets();
}
});
}
int[][] state = new int[][] { // unchecked
new int[] { -android.R.attr.state_checked }, // pressed
new int[] { android.R.attr.state_checked } };
int[] color = new int[] { Color.BLACK, Color.BLACK };
int[] iconcolor = new int[] { Color.GRAY, Color.BLACK };
navView.setItemTextColor(new ColorStateList(state, color));
navView.setItemIconTintList(new ColorStateList(state, iconcolor));
//主题变色
MenuItem item = navView.getMenu().findItem(R.id.nav_theme);
mThemeSwitch = (SwitchCompat) MenuItemCompat.getActionView(item).findViewById(R.id.view_switch);
mThemeSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mThemeSwitch.setChecked(isChecked);
if (isChecked) {
setThemeColor(Color.GREEN);
} else {
setThemeColor(getResources().getColor(R.color.colorPrimaryDark));
}
}
});
}
use of android.support.v7.widget.SwitchCompat in project Notes by Elder-Wu.
the class IosBottomDialogFragment method onCreateView.
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.fragment_bottom_dialog, container, false);
rootView.findViewById(R.id.fragment_ios_bottom_dialog_btn1).setOnClickListener(this);
rootView.findViewById(R.id.fragment_ios_bottom_dialog_btn2).setOnClickListener(this);
rootView.findViewById(R.id.fragment_ios_bottom_dialog_btn3).setOnClickListener(this);
rootView.findViewById(R.id.fragment_ios_bottom_dialog_btn4).setOnClickListener(this);
rootView.findViewById(R.id.fragment_ios_bottom_dialog_btn5).setOnClickListener(this);
rootView.findViewById(R.id.fragment_ios_bottom_dialog_btn6).setOnClickListener(this);
String str1 = "Hello Shanbay";
String str2 = ";a sh *if iao;h";
String str3 = "Hahahah ** he hei xi xiixi";
String str4 = "**as;higoan* e;v**se;viauhfid*";
handle(str1);
handle(str2);
handle(str3);
handle(str4);
Observable.timer(5, TimeUnit.SECONDS).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<Long>() {
@Override
public void call(Long aLong) {
TextView textView = (TextView) rootView.findViewById(R.id.xxxx);
textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
AppUtils.showToast("成功了");
}
});
final ProgressChartView chartView = (ProgressChartView) rootView.findViewById(R.id.chart);
ArrayList<ProgressChartView.Data> mRawDataList = new ArrayList<>();
mRawDataList.add(new ProgressChartView.Data("Mar 01", 3111));
// mRawDataList.add(new Data("Mar 02", 0));
// mRawDataList.add(new Data("Mar 03", 0));
// mRawDataList.add(new Data("Mar 04", 0));
// mRawDataList.add(new Data("Mar 05", 0));
// mRawDataList.add(new Data("Mar 06", 0));
// mRawDataList.add(new Data("Mar 07", 0));
mRawDataList.add(new ProgressChartView.Data("Mar 02", 3115));
mRawDataList.add(new ProgressChartView.Data("Mar 03", 3278));
mRawDataList.add(new ProgressChartView.Data("Mar 04", 3376));
mRawDataList.add(new ProgressChartView.Data("Mar 05", 3489));
mRawDataList.add(new ProgressChartView.Data("Mar 06", 3789));
mRawDataList.add(new ProgressChartView.Data("Mar 07", 3788));
chartView.setData(mRawDataList);
chartView.setColor(Color.RED);
SwitchCompat switchCompat = (SwitchCompat) rootView.findViewById(R.id.switch_btn);
switchCompat.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
chartView.showAllHintView();
} else {
chartView.removeAllHintView();
}
}
});
return rootView;
}
Aggregations