Java Code Examples for android.widget.ImageButton#setBackgroundResource()

The following examples show how to use android.widget.ImageButton#setBackgroundResource() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DrawForExpandLayout.java    From AssistantBySDK with Apache License 2.0 6 votes vote down vote up
/**
 * <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);
}
 
Example 2
Source File: ScheduledTasksAddActivity.java    From FreezeYou with Apache License 2.0 6 votes vote down vote up
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();
                }
            }
        }
    });
}
 
Example 3
Source File: ApiListActivity.java    From AutoTest with MIT License 5 votes vote down vote up
@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();
}
 
Example 4
Source File: DialogBase.java    From microMathematics with GNU General Public License v3.0 5 votes vote down vote up
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);
}
 
Example 5
Source File: AudioPlayerActivity.java    From Dashchan with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 6
Source File: EnterPasswordActivity.java    From TuentiTV with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 7
Source File: NA_Native.java    From test-samples with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example 8
Source File: ZenMenuAdapter.java    From zen4android with MIT License 5 votes vote down vote up
@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;
}
 
Example 9
Source File: WebViewDialog.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
/***
 * 初始化需要的控件
 * @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);
}
 
Example 10
Source File: ViewHolder.java    From o2oa with GNU Affero General Public License v3.0 4 votes vote down vote up
public ViewHolder setImageButtonBackground(int viewId, int resId) {
	ImageButton view = getView(viewId);
	view.setBackgroundResource(resId);
	return this;
}
 
Example 11
Source File: CommonRecyclerViewHolder.java    From o2oa with GNU Affero General Public License v3.0 4 votes vote down vote up
public CommonRecyclerViewHolder setImageButtonBackground(int viewId, int resId) {
    ImageButton view = getView(viewId);
    view.setBackgroundResource(resId);
    return this;
}
 
Example 12
Source File: EmojiPalettesView.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 4 votes vote down vote up
@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);
}
 
Example 13
Source File: RichEditWidgetView.java    From android-notepad with MIT License 4 votes vote down vote up
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));
}
 
Example 14
Source File: RichEditWidgetView.java    From android-notepad with MIT License 4 votes vote down vote up
private void setActionOff(ImageButton view){
	view.setBackgroundResource(0);
	view.setColorFilter(App.CONTEXT.getResources().getColor(R.color.md_blue_grey_300));
}
 
Example 15
Source File: EmojiPalettesView.java    From Indic-Keyboard with Apache License 2.0 4 votes vote down vote up
@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);
}