当前位置: 首页>>代码示例>>Java>>正文


Java SwitchCompat.setId方法代码示例

本文整理汇总了Java中android.support.v7.widget.SwitchCompat.setId方法的典型用法代码示例。如果您正苦于以下问题:Java SwitchCompat.setId方法的具体用法?Java SwitchCompat.setId怎么用?Java SwitchCompat.setId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.support.v7.widget.SwitchCompat的用法示例。


在下文中一共展示了SwitchCompat.setId方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addSwitch

import android.support.v7.widget.SwitchCompat; //导入方法依赖的package包/类
/**
 * Creates a standard toggle switch and adds it to the layout.
 *
 * -------------------------------------------------
 * | ICON | MESSAGE                       | TOGGLE |
 * -------------------------------------------------
 * If an icon is not provided, the ImageView that would normally show it is hidden.
 *
 * @param iconResourceId ID of the drawable to use for the icon, or 0 to hide the ImageView.
 * @param iconColorId    ID of the tint color for the icon, or 0 for default.
 * @param toggleMessage  Message to display for the toggle.
 * @param toggleId       ID to use for the toggle.
 * @param isChecked      Whether the toggle should start off checked.
 */
public View addSwitch(int iconResourceId, int iconColorId, CharSequence toggleMessage,
        int toggleId, boolean isChecked) {
    LinearLayout switchLayout = (LinearLayout) LayoutInflater.from(getContext()).inflate(
            R.layout.infobar_control_toggle, this, false);
    addView(switchLayout, new ControlLayoutParams());

    ImageView iconView = (ImageView) switchLayout.findViewById(R.id.control_icon);
    if (iconResourceId == 0) {
        switchLayout.removeView(iconView);
    } else {
        iconView.setImageResource(iconResourceId);
        if (iconColorId != 0) {
            iconView.setColorFilter(
                    ApiCompatibilityUtils.getColor(getResources(), iconColorId));
        }
    }

    TextView messageView = (TextView) switchLayout.findViewById(R.id.control_message);
    messageView.setText(toggleMessage);

    SwitchCompat switchView =
            (SwitchCompat) switchLayout.findViewById(R.id.control_toggle_switch);
    switchView.setId(toggleId);
    switchView.setChecked(isChecked);

    return switchLayout;
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:42,代码来源:InfoBarControlLayout.java

示例2: init

import android.support.v7.widget.SwitchCompat; //导入方法依赖的package包/类
@Override
public void init() {
    super.init();

    mSwitch = new SwitchCompat(getContext()) {

        boolean isTouched = false;

        @Override
        public void setChecked(boolean checked) {
            if ( isTouched || mForced ) {
                super.setChecked(checked);

                if ( isTouched && mListener != null ) {
                    isTouched = false;
                    mListener.onCheckedChanged(this, checked);
                }

                mForced = false;

            }
        }

        @Override
        public boolean onTouchEvent(MotionEvent ev) {
            isTouched = true;
            return super.onTouchEvent(ev);
        }
    };
    mSwitch.setId(R.id.settings_switch);
    RelativeLayout.LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    mSwitch.setLayoutParams(lp);

    lp = (LayoutParams) mTextView.getLayoutParams();
    lp.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
    lp.addRule(RelativeLayout.LEFT_OF, mSwitch.getId());
    mTextView.setLayoutParams(lp);

    int p = getResources().getDimensionPixelOffset(R.dimen.eight_dp) / 4;
    mSwitch.setPadding(p, p, p, p);

    addView(mSwitch);
}
 
开发者ID:timothymiko,项目名称:narrate-android,代码行数:45,代码来源:SwitchPreference.java


注:本文中的android.support.v7.widget.SwitchCompat.setId方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。