android.widget.ImageButton# setBackgroundResource ( ) 源码实例Demo

下面列出了android.widget.ImageButton# setBackgroundResource ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: AssistantBySDK   文件: DrawForExpandLayout.java
/**
 * <ImageButton
 android:id="@+id/ancp_poi_list_drap_bar"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:background="@color/new_line_border"
 android:src="@drawable/bnav_poi_list_drag"
 android:paddingBottom="10dp"
 android:paddingTop="10dp"
 />
 */
private void init(){
    DisplayMetrics metrics=getContext().getResources().getDisplayMetrics();
    density=metrics.density;
    sHeight=metrics.heightPixels;
    minHeight=dp2px(50);
    Log.i(TAG,"sHeight="+sHeight+",minHeight="+50);
    drawBar=new ImageButton(getContext());
    LayoutParams layoutParams=new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT);
    drawBar.setBackgroundResource(R.color.base_blue_translucent);
    drawBar.setImageResource(R.drawable.bnav_poi_list_drag);
    drawBar.setPadding(0, dp2px(10), 0, dp2px(10));
    addView(drawBar, 0, layoutParams);

    drawBar.setOnTouchListener(drawTouchListener);
}
 
源代码2 项目: FreezeYou   文件: ScheduledTasksAddActivity.java
private void prepareSaveButton(final int id) {
    final ImageButton saveButton = findViewById(R.id.staa_saveButton);
    saveButton.setBackgroundResource(Build.VERSION.SDK_INT < 21 ? getThemeFabDotBackground(ScheduledTasksAddActivity.this) : R.drawable.oval_ripple);
    saveButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
            if (isTimeTask) {
                if (saveTimeTaskData(defaultSharedPreferences, id)) {
                    finish();
                }
            } else {
                if (saveTriggerTaskData(defaultSharedPreferences, id)) {
                    finish();
                }
            }
        }
    });
}
 
源代码3 项目: AutoTest   文件: ApiListActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_api_list);


    activityApiListLayoutTop = (LinearLayout) findViewById(R.id.activity_api_list_layout_top);
    back = (ImageButton) findViewById(R.id.back);
    input = (EditText) findViewById(R.id.input);
    spinner = (Spinner) findViewById(R.id.spinner);
    test = (ImageButton) findViewById(R.id.test);
    codeClick = (LinearLayout) findViewById(R.id.code_click);
    timeClick = (LinearLayout) findViewById(R.id.time_click);
    statusClick = (LinearLayout) findViewById(R.id.status_click);
    testClick = (LinearLayout) findViewById(R.id.test_click);
    recyclerview = (RecyclerView) findViewById(R.id.recyclerview);

    back.setOnClickListener(this);
    testClick.setOnClickListener(this);
    statusClick.setOnClickListener(this);
    codeClick.setOnClickListener(this);
    timeClick.setOnClickListener(this);

    presenter = new ApiListActivityPresenter();
    dialogAsk = new DialogAsk(this, R.style.RcDialog);
    /********************************************************************************/
    recyclerview.setLayoutManager(new LinearLayoutManager(this));
    mainAdapter = new APIListAdapter(R.layout.item_api_list_layout);
    recyclerview.setAdapter(mainAdapter);
    /********************************************************************************/
    presenter.sortDialogTXT(checkedList,statusList,timeList,codeList);
    setListener();
    test.setBackgroundResource(R.mipmap.icon_test_stop);
    presenter.prepareTest();
}
 
源代码4 项目: microMathematics   文件: DialogBase.java
protected void setButtonSelected(ImageButton b, boolean isSelected)
{
    b.setSelected(isSelected);
    if (b.isSelected())
    {
        b.setBackgroundResource(R.drawable.formula_term_border);
        CompatUtils.setDrawableColorAttr(getContext(), b.getBackground(), R.attr.colorAccent);
    }
    else
    {
        b.setBackgroundResource(android.R.color.transparent);
    }
    ViewUtils.setImageButtonColorAttr(getContext(), b,
            b.isSelected() ? R.attr.colorAccent : R.attr.colorDialogContent);
}
 
源代码5 项目: Dashchan   文件: AudioPlayerActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	context = new ContextThemeWrapper(this, Preferences.getThemeResource());
	setVolumeControlStream(AudioManager.STREAM_MUSIC);
	float density = ResourceUtils.obtainDensity(this);
	LinearLayout linearLayout = new LinearLayout(context);
	linearLayout.setOrientation(LinearLayout.VERTICAL);
	int padding = getResources().getDimensionPixelSize(R.dimen.dialog_padding_view);
	linearLayout.setPadding(padding, padding, padding, C.API_LOLLIPOP ? (int) (8f * density) : padding);
	textView = new TextView(context, null, android.R.attr.textAppearanceListItem);
	linearLayout.addView(textView, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
	textView.setPadding(0, 0, 0, 0);
	textView.setEllipsize(TextUtils.TruncateAt.END);
	textView.setSingleLine(true);
	LinearLayout horizontal = new LinearLayout(context);
	horizontal.setOrientation(LinearLayout.HORIZONTAL);
	horizontal.setGravity(Gravity.CENTER_VERTICAL);
	horizontal.setPadding(0, (int) (16f * density), 0, 0);
	linearLayout.addView(horizontal, LinearLayout.LayoutParams.MATCH_PARENT,
			LinearLayout.LayoutParams.WRAP_CONTENT);
	seekBar = new SeekBar(context);
	horizontal.addView(seekBar, new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1));
	seekBar.setPadding((int) (8f * density), 0, (int) (16f * density), 0);
	seekBar.setOnSeekBarChangeListener(this);
	button = new ImageButton(context);
	horizontal.addView(button, (int) (48f * density), (int) (48f * density));
	button.setBackgroundResource(ResourceUtils.getResourceId(context,
			android.R.attr.listChoiceBackgroundIndicator, 0));
	setPlayState(false);
	button.setOnClickListener(this);
	alertDialog = new AlertDialog.Builder(context).setView(linearLayout).setOnCancelListener(this)
			.setPositiveButton(R.string.action_stop, this).show();
	IntentFilter intentFilter = new IntentFilter();
	intentFilter.addAction(AudioPlayerService.ACTION_TOGGLE);
	intentFilter.addAction(AudioPlayerService.ACTION_CANCEL);
	LocalBroadcastManager.getInstance(this).registerReceiver(audioPlayerReceiver, intentFilter);
	bindService(new Intent(this, AudioPlayerService.class), this, 0);
}
 
源代码6 项目: TuentiTV   文件: EnterPasswordActivity.java
private void showPasswordElement(int passwordElementResource) {
  ImageButton ib_password_element = (ImageButton) getCurrentFocus();
  ib_password_element.setImageResource(passwordElementResource);
  ib_password_element.setBackgroundResource(R.color.transparent);
  LinearLayout.LayoutParams lp =
      (LinearLayout.LayoutParams) ib_password_element.getLayoutParams();
  lp.height = LinearLayout.LayoutParams.WRAP_CONTENT;
  ib_password_element.setLayoutParams(lp);
  updatePasswordElementWithAsterisk(ib_password_element, CHANGE_PASSWORD_TIME_IN_MILLIS);
}
 
源代码7 项目: test-samples   文件: NA_Native.java
private void tileClick(int x, int y) {
    ImageButton tile = tiles[x][y];

    if (tile.getTag() == STATE_HIGHLIGHTED) {
        swap(swapTile[0], swapTile[1], x, y);
        swapTile = new int[]{-1, -1};
        incrementRound();
    } else {
        swapTile = new int[]{x, y};
        tile.setTag(STATE_PRESSED);
        tile.setEnabled(false);
        tile.setBackgroundResource(R.drawable.button_game_pressed);
        highlightNeighbours(x, y);
    }
}
 
源代码8 项目: zen4android   文件: ZenMenuAdapter.java
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
		View convertView, ViewGroup parent) {
	Map<String, String> map = (Map<String, String>)mHeaders.get(groupPosition);
	String text = (String)map.get("name");
	if(convertView == null) {
		convertView = mInflater.inflate(R.layout.zen_menu_group, null);			
	}
	ImageButton itemLeft = (ImageButton)convertView.findViewById(R.id.zen_menu_header_left);
	Button itemRight = (Button)convertView.findViewById(R.id.zen_menu_header_right);
	itemRight.setText(text);
	
	itemLeft.setImageResource(R.drawable.menu_right_arrow);
	if(isExpanded) {
		itemLeft.setImageResource(R.drawable.menu_down_arrow);
	}
	
	int background = menu_item_backgrounds[groupPosition%9];
	itemLeft.setBackgroundResource(background);
	itemRight.setBackgroundResource(background);
	itemLeft.setFocusable(false);
	itemRight.setFocusable(false);
	itemLeft.setClickable(false);
	itemRight.setClickable(false);
	
	
	
	return convertView;
}
 
源代码9 项目: VideoOS-Android-SDK   文件: WebViewDialog.java
/***
 * 初始化需要的控件
 * @param context
 */
@JavascriptInterface
private void initView(final Context context) {
    //父控件
    mParent = new FrameLayout(context);
    //设置背景
    mParent.setBackgroundColor(Color.parseColor("#F0F0F0"));
    //大小参数
    FrameLayout.LayoutParams mParentParams =
            new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
                    FrameLayout.LayoutParams.MATCH_PARENT);
    //设置参数
    mParent.setLayoutParams(mParentParams);
    //添加子控件
    FrameLayout mTopLayout = new FrameLayout(context);
    //设置背景
    mTopLayout.setBackgroundColor(Color.parseColor("#2b2b2b"));
    int mTopHight = VenvyUIUtil.dip2px(context, 45);
    //大小参数
    FrameLayout.LayoutParams mTopParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, mTopHight);
    //TOP区域添加返回按钮
    ImageButton mBackView = new ImageButton(context);
    //设置点击事件
    mBackView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dismiss();
        }
    });
    //设置本地图片
    mBackView.setBackgroundResource(VenvyResourceUtil.getDrawableOrmipmapId(
            context, "venvy_os_outside_link_back"));
    //
    mBackView.setScaleType(ImageView.ScaleType.FIT_CENTER);
    //大小参数
    FrameLayout.LayoutParams mBackParams = new FrameLayout.LayoutParams(mTopHight, mTopHight);
    mTopLayout.addView(mBackView, mBackParams);
    //进度条区域
    final ProgressBar mProBarView = new ProgressBar(context, null,
            android.R.attr.progressBarStyleHorizontal);
    //进度清空
    mProBarView.setProgress(0);
    //设置加载进度的颜色
    mProBarView.setProgressDrawable(context.getResources().getDrawable(
            VenvyResourceUtil.getDrawableId(context,
                    "venvy_library_webview_load_bg")));// 设置
    //大小参数
    FrameLayout.LayoutParams mBarParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, VenvyUIUtil.dip2px(context, 3));
    //顶部位置
    mBarParams.topMargin = mTopHight;
    //创建WebView控件
    mWebView = WebViewFactory.createWebView(context);
    //大小参数
    final FrameLayout.LayoutParams mWebParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
    //距离顶部位置
    mWebParams.topMargin = mTopHight;
    //加载监听
    mWebView.setWebChromeClient(new IVenvyWebChromeClient() {
        @Override
        public void onProgressChanged(View view, int newProgress) {
            if (newProgress >= 100) {
                mParent.removeView(mProBarView);
            } else {
                mProBarView.setProgress(newProgress);
            }
        }
    });

    mParent.addView(mTopLayout, mTopParams);
    if (mWebView instanceof View) {
        FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        ((View) mWebView).setLayoutParams(params);
        mParent.addView((View) mWebView);
    }
    //添加进度条
    mParent.addView(mProBarView, mBarParams);
    //加载布局
    setContentView(mParent);
}
 
源代码10 项目: o2oa   文件: ViewHolder.java
public ViewHolder setImageButtonBackground(int viewId, int resId) {
	ImageButton view = getView(viewId);
	view.setBackgroundResource(resId);
	return this;
}
 
源代码11 项目: o2oa   文件: CommonRecyclerViewHolder.java
public CommonRecyclerViewHolder setImageButtonBackground(int viewId, int resId) {
    ImageButton view = getView(viewId);
    view.setBackgroundResource(resId);
    return this;
}
 
源代码12 项目: AOSP-Kayboard-7.1.2   文件: EmojiPalettesView.java
@Override
protected void onFinishInflate() {
    mTabHost = (TabHost)findViewById(R.id.emoji_category_tabhost);
    mTabHost.setup();
    for (final EmojiCategory.CategoryProperties properties
            : mEmojiCategory.getShownCategories()) {
        addTab(mTabHost, properties.mCategoryId);
    }
    mTabHost.setOnTabChangedListener(this);
    final TabWidget tabWidget = mTabHost.getTabWidget();
    tabWidget.setStripEnabled(mCategoryIndicatorEnabled);
    if (mCategoryIndicatorEnabled) {
        // On TabWidget's strip, what looks like an indicator is actually a background.
        // And what looks like a background are actually left and right drawables.
        tabWidget.setBackgroundResource(mCategoryIndicatorDrawableResId);
        tabWidget.setLeftStripDrawable(mCategoryIndicatorBackgroundResId);
        tabWidget.setRightStripDrawable(mCategoryIndicatorBackgroundResId);
    }

    mEmojiPalettesAdapter = new EmojiPalettesAdapter(mEmojiCategory, this);

    mEmojiPager = (ViewPager)findViewById(R.id.emoji_keyboard_pager);
    mEmojiPager.setAdapter(mEmojiPalettesAdapter);
    mEmojiPager.setOnPageChangeListener(this);
    mEmojiPager.setOffscreenPageLimit(0);
    mEmojiPager.setPersistentDrawingCache(PERSISTENT_NO_CACHE);
    mEmojiLayoutParams.setPagerProperties(mEmojiPager);

    mEmojiCategoryPageIndicatorView =
            (EmojiCategoryPageIndicatorView)findViewById(R.id.emoji_category_page_id_view);
    mEmojiCategoryPageIndicatorView.setColors(
            mCategoryPageIndicatorColor, mCategoryPageIndicatorBackground);
    mEmojiLayoutParams.setCategoryPageIdViewProperties(mEmojiCategoryPageIndicatorView);

    setCurrentCategoryId(mEmojiCategory.getCurrentCategoryId(), true /* force */);

    final LinearLayout actionBar = (LinearLayout)findViewById(R.id.emoji_action_bar);
    mEmojiLayoutParams.setActionBarProperties(actionBar);

    // deleteKey depends only on OnTouchListener.
    mDeleteKey = (ImageButton)findViewById(R.id.emoji_keyboard_delete);
    mDeleteKey.setBackgroundResource(mFunctionalKeyBackgroundId);
    mDeleteKey.setTag(Constants.CODE_DELETE);
    mDeleteKey.setOnTouchListener(mDeleteKeyOnTouchListener);

    // {@link #mAlphabetKeyLeft}, {@link #mAlphabetKeyRight, and spaceKey depend on
    // {@link View.OnClickListener} as well as {@link View.OnTouchListener}.
    // {@link View.OnTouchListener} is used as the trigger of key-press, while
    // {@link View.OnClickListener} is used as the trigger of key-release which does not occur
    // if the event is canceled by moving off the finger from the view.
    // The text on alphabet keys are set at
    // {@link #startEmojiPalettes(String,int,float,Typeface)}.
    mAlphabetKeyLeft = (TextView)findViewById(R.id.emoji_keyboard_alphabet_left);
    mAlphabetKeyLeft.setBackgroundResource(mFunctionalKeyBackgroundId);
    mAlphabetKeyLeft.setTag(Constants.CODE_ALPHA_FROM_EMOJI);
    mAlphabetKeyLeft.setOnTouchListener(this);
    mAlphabetKeyLeft.setOnClickListener(this);
    mAlphabetKeyRight = (TextView)findViewById(R.id.emoji_keyboard_alphabet_right);
    mAlphabetKeyRight.setBackgroundResource(mFunctionalKeyBackgroundId);
    mAlphabetKeyRight.setTag(Constants.CODE_ALPHA_FROM_EMOJI);
    mAlphabetKeyRight.setOnTouchListener(this);
    mAlphabetKeyRight.setOnClickListener(this);
    mSpacebar = findViewById(R.id.emoji_keyboard_space);
    mSpacebar.setBackgroundResource(mSpacebarBackgroundId);
    mSpacebar.setTag(Constants.CODE_SPACE);
    mSpacebar.setOnTouchListener(this);
    mSpacebar.setOnClickListener(this);
    mEmojiLayoutParams.setKeyProperties(mSpacebar);
    mSpacebarIcon = findViewById(R.id.emoji_keyboard_space_icon);
}
 
源代码13 项目: android-notepad   文件: RichEditWidgetView.java
private void setActionOn(ImageButton view){
	view.setBackgroundResource(R.drawable.background_rich_edit_action_on);
	view.setColorFilter(App.CONTEXT.getResources().getColor(R.color.md_blue_grey_500));
}
 
源代码14 项目: android-notepad   文件: RichEditWidgetView.java
private void setActionOff(ImageButton view){
	view.setBackgroundResource(0);
	view.setColorFilter(App.CONTEXT.getResources().getColor(R.color.md_blue_grey_300));
}
 
源代码15 项目: Indic-Keyboard   文件: EmojiPalettesView.java
@Override
protected void onFinishInflate() {
    mTabHost = (TabHost)findViewById(R.id.emoji_category_tabhost);
    mTabHost.setup();
    for (final EmojiCategory.CategoryProperties properties
            : mEmojiCategory.getShownCategories()) {
        addTab(mTabHost, properties.mCategoryId);
    }
    mTabHost.setOnTabChangedListener(this);
    final TabWidget tabWidget = mTabHost.getTabWidget();
    tabWidget.setStripEnabled(mCategoryIndicatorEnabled);
    if (mCategoryIndicatorEnabled) {
        // On TabWidget's strip, what looks like an indicator is actually a background.
        // And what looks like a background are actually left and right drawables.
        tabWidget.setBackgroundResource(mCategoryIndicatorDrawableResId);
        tabWidget.setLeftStripDrawable(mCategoryIndicatorBackgroundResId);
        tabWidget.setRightStripDrawable(mCategoryIndicatorBackgroundResId);
    }

    mEmojiPalettesAdapter = new EmojiPalettesAdapter(mEmojiCategory, this);

    mEmojiPager = (ViewPager)findViewById(R.id.emoji_keyboard_pager);
    mEmojiPager.setAdapter(mEmojiPalettesAdapter);
    mEmojiPager.setOnPageChangeListener(this);
    mEmojiPager.setOffscreenPageLimit(0);
    mEmojiPager.setPersistentDrawingCache(PERSISTENT_NO_CACHE);
    mEmojiLayoutParams.setPagerProperties(mEmojiPager);

    mEmojiCategoryPageIndicatorView =
            (EmojiCategoryPageIndicatorView)findViewById(R.id.emoji_category_page_id_view);
    mEmojiCategoryPageIndicatorView.setColors(
            mCategoryPageIndicatorColor, mCategoryPageIndicatorBackground);
    mEmojiLayoutParams.setCategoryPageIdViewProperties(mEmojiCategoryPageIndicatorView);

    setCurrentCategoryId(mEmojiCategory.getCurrentCategoryId(), true /* force */);

    final LinearLayout actionBar = (LinearLayout)findViewById(R.id.emoji_action_bar);
    mEmojiLayoutParams.setActionBarProperties(actionBar);

    // deleteKey depends only on OnTouchListener.
    mDeleteKey = (ImageButton)findViewById(R.id.emoji_keyboard_delete);
    mDeleteKey.setBackgroundResource(mFunctionalKeyBackgroundId);
    mDeleteKey.setTag(Constants.CODE_DELETE);
    mDeleteKey.setOnTouchListener(mDeleteKeyOnTouchListener);

    // {@link #mAlphabetKeyLeft}, {@link #mAlphabetKeyRight, and spaceKey depend on
    // {@link View.OnClickListener} as well as {@link View.OnTouchListener}.
    // {@link View.OnTouchListener} is used as the trigger of key-press, while
    // {@link View.OnClickListener} is used as the trigger of key-release which does not occur
    // if the event is canceled by moving off the finger from the view.
    // The text on alphabet keys are set at
    // {@link #startEmojiPalettes(String,int,float,Typeface)}.
    mAlphabetKeyLeft = (TextView)findViewById(R.id.emoji_keyboard_alphabet_left);
    mAlphabetKeyLeft.setBackgroundResource(mFunctionalKeyBackgroundId);
    mAlphabetKeyLeft.setTag(Constants.CODE_ALPHA_FROM_EMOJI);
    mAlphabetKeyLeft.setOnTouchListener(this);
    mAlphabetKeyLeft.setOnClickListener(this);
    mAlphabetKeyRight = (TextView)findViewById(R.id.emoji_keyboard_alphabet_right);
    mAlphabetKeyRight.setBackgroundResource(mFunctionalKeyBackgroundId);
    mAlphabetKeyRight.setTag(Constants.CODE_ALPHA_FROM_EMOJI);
    mAlphabetKeyRight.setOnTouchListener(this);
    mAlphabetKeyRight.setOnClickListener(this);
    mSpacebar = findViewById(R.id.emoji_keyboard_space);
    mSpacebar.setBackgroundResource(mSpacebarBackgroundId);
    mSpacebar.setTag(Constants.CODE_SPACE);
    mSpacebar.setOnTouchListener(this);
    mSpacebar.setOnClickListener(this);
    mEmojiLayoutParams.setKeyProperties(mSpacebar);
    mSpacebarIcon = findViewById(R.id.emoji_keyboard_space_icon);
}