setMinWidth ( )源码实例Demo

android.widget.Button#setMinWidth ( )源码实例Demo

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

源代码1 项目: video-tutorial-code   文件: MainActivity.java
private void lockButtonSizes() {
   	for (int row = 0; row < NUM_ROWS; row++) {
   		for (int col = 0; col < NUM_COLS; col++) {
   			Button button = buttons[row][col];
   			
   			int width = button.getWidth();
   			button.setMinWidth(width);
   			button.setMaxWidth(width);
   			
			int height = button.getHeight();
			button.setMinHeight(height);
			button.setMaxHeight(height);
   		}
   	}		
}
 
源代码2 项目: colorpicker   文件: ColorPicker.java
/**
 * add a new Button using default style
 *
 * @param text     title of button
 * @param listener OnButtonListener
 * @return this
 */
public ColorPicker addListenerButton(String text, final OnButtonListener listener) {
    if (mContext == null)
        return this;

    Context context = mContext.get();
    if (context == null)
        return this;


    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT
    );

    params.setMargins(dip2px(10, context), 0, 0, 0);
    Button button = new Button(context);
    button.setMinWidth(getDimensionDp(R.dimen.action_button_min_width, context));
    button.setMinimumWidth(getDimensionDp(R.dimen.action_button_min_width, context));
    button.setPadding(
            getDimensionDp(R.dimen.action_button_padding_horizontal, context) + dip2px(5, context), 0,
            getDimensionDp(R.dimen.action_button_padding_horizontal, context) + dip2px(5, context), 0);
    button.setBackgroundResource(R.drawable.button);
    button.setTextSize(getDimensionDp(R.dimen.action_button_text_size, context));
    button.setTextColor(ContextCompat.getColor(context, R.color.black_de));

    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            listener.onClick(v, colorViewAdapter.getColorPosition(), colorViewAdapter.getColorSelected());
        }
    });
    button.setText(text);
    if (button.getParent() != null)
        buttons_layout.removeView(button);

    buttons_layout.addView(button);
    button.setLayoutParams(params);
    return this;
}
 
源代码3 项目: QuantityView   文件: QuantityView.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void init(AttributeSet attrs, int defStyle) {
    final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.QuantityView, defStyle, 0);

    addButtonText = getResources().getString(R.string.qv_add);
    if (a.hasValue(R.styleable.QuantityView_qv_addButtonText)) {
        addButtonText = a.getString(R.styleable.QuantityView_qv_addButtonText);
    }
    addButtonBackground = ContextCompat.getDrawable(getContext(), R.drawable.qv_btn_selector);
    if (a.hasValue(R.styleable.QuantityView_qv_addButtonBackground)) {
        addButtonBackground = a.getDrawable(R.styleable.QuantityView_qv_addButtonBackground);
    }
    addButtonTextColor = a.getColor(R.styleable.QuantityView_qv_addButtonTextColor, Color.BLACK);

    removeButtonText = getResources().getString(R.string.qv_remove);
    if (a.hasValue(R.styleable.QuantityView_qv_removeButtonText)) {
        removeButtonText = a.getString(R.styleable.QuantityView_qv_removeButtonText);
    }
    removeButtonBackground = ContextCompat.getDrawable(getContext(), R.drawable.qv_btn_selector);
    if (a.hasValue(R.styleable.QuantityView_qv_removeButtonBackground)) {
        removeButtonBackground = a.getDrawable(R.styleable.QuantityView_qv_removeButtonBackground);
    }
    removeButtonTextColor = a.getColor(R.styleable.QuantityView_qv_removeButtonTextColor, Color.BLACK);

    quantity = a.getInt(R.styleable.QuantityView_qv_quantity, 0);
    maxQuantity = a.getInt(R.styleable.QuantityView_qv_maxQuantity, Integer.MAX_VALUE);
    minQuantity = a.getInt(R.styleable.QuantityView_qv_minQuantity, 0);

    quantityPadding = (int) a.getDimension(R.styleable.QuantityView_qv_quantityPadding, pxFromDp(24));
    quantityTextColor = a.getColor(R.styleable.QuantityView_qv_quantityTextColor, Color.BLACK);
    quantityBackground = ContextCompat.getDrawable(getContext(), R.drawable.qv_bg_selector);
    if (a.hasValue(R.styleable.QuantityView_qv_quantityBackground)) {
        quantityBackground = a.getDrawable(R.styleable.QuantityView_qv_quantityBackground);
    }

    quantityDialog = a.getBoolean(R.styleable.QuantityView_qv_quantityDialog, true);

    a.recycle();
    int dp10 = pxFromDp(10);

    mButtonAdd = new Button(getContext());
    mButtonAdd.setGravity(Gravity.CENTER);
    mButtonAdd.setPadding(dp10, dp10, dp10, dp10);
    mButtonAdd.setMinimumHeight(0);
    mButtonAdd.setMinimumWidth(0);
    mButtonAdd.setMinHeight(0);
    mButtonAdd.setMinWidth(0);
    setAddButtonBackground(addButtonBackground);
    setAddButtonText(addButtonText);
    setAddButtonTextColor(addButtonTextColor);

    mButtonRemove = new Button(getContext());
    mButtonRemove.setGravity(Gravity.CENTER);
    mButtonRemove.setPadding(dp10, dp10, dp10, dp10);
    mButtonRemove.setMinimumHeight(0);
    mButtonRemove.setMinimumWidth(0);
    mButtonRemove.setMinHeight(0);
    mButtonRemove.setMinWidth(0);
    setRemoveButtonBackground(removeButtonBackground);
    setRemoveButtonText(removeButtonText);
    setRemoveButtonTextColor(removeButtonTextColor);

    mTextViewQuantity = new TextView(getContext());
    mTextViewQuantity.setGravity(Gravity.CENTER);
    setQuantityTextColor(quantityTextColor);
    setQuantity(quantity);
    setQuantityBackground(quantityBackground);
    setQuantityPadding(quantityPadding);

    setOrientation(HORIZONTAL);

    addView(mButtonRemove, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    addView(mTextViewQuantity, LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
    addView(mButtonAdd, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

    mButtonAdd.setOnClickListener(this);
    mButtonRemove.setOnClickListener(this);
    mTextViewQuantity.setOnClickListener(this);
}
 
源代码4 项目: Dashchan   文件: GalleryActivity.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void displayShowcase() {
	if (showcaseDestroyRunnable != null || !Preferences.isShowcaseGalleryEnabled()) {
		return;
	}

	float density = ResourceUtils.obtainDensity(this);
	FrameLayout frameLayout = new FrameLayout(this);
	frameLayout.setBackgroundColor(0xf0222222);
	LinearLayout linearLayout = new LinearLayout(this);
	linearLayout.setOrientation(LinearLayout.VERTICAL);
	frameLayout.addView(linearLayout, new FrameLayout.LayoutParams((int) (304f * density),
			FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.CENTER));

	Button button = new Button(this, null, android.R.attr.borderlessButtonStyle);
	button.setText(R.string.action_got_it);
	button.setMinimumWidth(0);
	button.setMinWidth(0);

	int paddingLeft = button.getPaddingLeft();
	int paddingRight = button.getPaddingRight();
	int paddingTop = button.getPaddingTop();
	int paddingBottom = Math.max(0, (int) (24f * density) - paddingTop);

	int[] messages = {R.string.message_showcase_context_menu, R.string.message_showcase_gallery};

	for (int resId : messages) {
		String[] message = getString(resId).split("\n");
		TextView textView1 = new TextView(this, null, android.R.attr.textAppearanceLarge);
		textView1.setText(message.length > 0 ? message[0] : null);
		textView1.setTypeface(GraphicsUtils.TYPEFACE_LIGHT);
		textView1.setPadding(paddingLeft, paddingTop, paddingRight, (int) (4f * density));
		TextView textView2 = new TextView(this, null, android.R.attr.textAppearanceSmall);
		textView2.setText(message.length > 1 ? message[1] : null);
		textView2.setPadding(paddingLeft, 0, paddingRight, paddingBottom);
		linearLayout.addView(textView1, LinearLayout.LayoutParams.MATCH_PARENT,
				LinearLayout.LayoutParams.WRAP_CONTENT);
		linearLayout.addView(textView2, LinearLayout.LayoutParams.MATCH_PARENT,
				LinearLayout.LayoutParams.WRAP_CONTENT);
	}

	linearLayout.addView(button, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);

	WindowManager windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
	WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
	layoutParams.format = PixelFormat.TRANSLUCENT;
	layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
	layoutParams.height = WindowManager.LayoutParams.MATCH_PARENT;
	layoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
			WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
	layoutParams.windowAnimations = R.style.Animation_Showcase;
	if (C.API_LOLLIPOP) {
		layoutParams.flags |= WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
	}
	windowManager.addView(frameLayout, layoutParams);

	showcaseDestroyRunnable = () -> {
		showcaseDestroyRunnable = null;
		Preferences.consumeShowcaseGallery();
		windowManager.removeView(frameLayout);
	};

	button.setOnClickListener(v -> showcaseDestroyRunnable.run());
}
 
源代码5 项目: Dashchan   文件: PostsPage.java
@Override
protected void onCreate() {
	Activity activity = getActivity();
	PullableListView listView = getListView();
	PageHolder pageHolder = getPageHolder();
	UiManager uiManager = getUiManager();
	hidePerformer = new HidePerformer();
	PostsExtra extra = getExtra();
	listView.setDivider(ResourceUtils.getDrawable(activity, R.attr.postsDivider, 0));
	ChanConfiguration.Board board = getChanConfiguration().safe().obtainBoard(pageHolder.boardName);
	if (board.allowPosting) {
		replyable = data -> getUiManager().navigator().navigatePosting(pageHolder.chanName, pageHolder.boardName,
				pageHolder.threadNumber, data);
	}
	PostsAdapter adapter = new PostsAdapter(activity, pageHolder.chanName, pageHolder.boardName, uiManager,
			replyable, hidePerformer, extra.userPostNumbers, listView);
	initAdapter(adapter, adapter);
	ImageLoader.getInstance().observable().register(this);
	listView.getWrapper().setPullSides(PullableWrapper.Side.BOTH);
	uiManager.observable().register(this);
	hidePerformer.setPostsProvider(adapter);

	Context darkStyledContext = new ContextThemeWrapper(activity, R.style.Theme_General_Main_Dark);
	searchController = new LinearLayout(darkStyledContext);
	searchController.setOrientation(LinearLayout.HORIZONTAL);
	searchController.setGravity(Gravity.CENTER_VERTICAL);
	float density = ResourceUtils.obtainDensity(getResources());
	int padding = (int) (10f * density);
	searchTextResult = new Button(darkStyledContext, null, android.R.attr.borderlessButtonStyle);
	searchTextResult.setTextSize(11f);
	if (!C.API_LOLLIPOP) {
		searchTextResult.setTypeface(null, Typeface.BOLD);
	}
	searchTextResult.setPadding((int) (14f * density), 0, (int) (14f * density), 0);
	searchTextResult.setMinimumWidth(0);
	searchTextResult.setMinWidth(0);
	searchTextResult.setOnClickListener(v -> showSearchDialog());
	searchController.addView(searchTextResult, LinearLayout.LayoutParams.WRAP_CONTENT,
			LinearLayout.LayoutParams.WRAP_CONTENT);
	ImageView backButtonView = new ImageView(darkStyledContext, null, android.R.attr.borderlessButtonStyle);
	backButtonView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
	backButtonView.setImageResource(obtainIcon(R.attr.actionBack));
	backButtonView.setPadding(padding, padding, padding, padding);
	backButtonView.setOnClickListener(v -> findBack());
	searchController.addView(backButtonView, (int) (48f * density), (int) (48f * density));
	ImageView forwardButtonView = new ImageView(darkStyledContext, null, android.R.attr.borderlessButtonStyle);
	forwardButtonView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
	forwardButtonView.setImageResource(obtainIcon(R.attr.actionForward));
	forwardButtonView.setPadding(padding, padding, padding, padding);
	forwardButtonView.setOnClickListener(v -> findForward());
	searchController.addView(forwardButtonView, (int) (48f * density), (int) (48f * density));
	if (C.API_LOLLIPOP) {
		for (int i = 0, last = searchController.getChildCount() - 1; i <= last; i++) {
			View view = searchController.getChildAt(i);
			LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) view.getLayoutParams();
			if (i == 0) {
				layoutParams.leftMargin = (int) (-6f * density);
			}
			if (i == last) {
				layoutParams.rightMargin = (int) (6f * density);
			} else {
				layoutParams.rightMargin = (int) (-6f * density);
			}
		}
	}

	scrollToPostNumber = pageHolder.initialPostNumber;
	FavoritesStorage.getInstance().getObservable().register(this);
	LocalBroadcastManager.getInstance(activity).registerReceiver(galleryPagerReceiver,
			new IntentFilter(C.ACTION_GALLERY_NAVIGATE_POST));
	boolean hasNewPostDatas = handleNewPostDatas();
	extra.forceRefresh = hasNewPostDatas || !pageHolder.initialFromCache;
	if (extra.cachedPosts != null && extra.cachedPostItems.size() > 0) {
		onDeserializePostsCompleteInternal(true, extra.cachedPosts, new ArrayList<>(extra.cachedPostItems), true);
	} else {
		deserializeTask = new DeserializePostsTask(this, pageHolder.chanName, pageHolder.boardName,
				pageHolder.threadNumber, extra.cachedPosts);
		deserializeTask.executeOnExecutor(DeserializePostsTask.THREAD_POOL_EXECUTOR);
		getListView().getWrapper().startBusyState(PullableWrapper.Side.BOTH);
		switchView(ViewType.PROGRESS, null);
	}
	pageHolder.setInitialPostsData(false, null);
}