第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

按鈕的背景不顯示

按鈕的背景不顯示

紅糖糍粑 2021-08-25 15:02:30
不顯示背景。如果按鈕沒有背景,則顯示 OK<?xml version="1.0" encoding="utf-8"?><android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:app="http://schemas.android.com/apk/res-auto"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:background="?attr/colorBackgroundFloating"    tools:context=".MainActivity"    tools:layout_editor_absoluteY="25dp">    <Button        android:id="@+id/button_1"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_centerInParent="true"        android:layout_weight="1"        android:background="@drawable/my_round_button"        android:onClick="onClick"        android:text="@string/button_1"        android:visibility="visible"        app:layout_constraintBottom_toBottomOf="parent"        app:layout_constraintEnd_toEndOf="parent"        app:layout_constraintStart_toStartOf="parent"        app:layout_constraintTop_toTopOf="parent" /></android.support.constraint.ConstraintLayout>當應(yīng)用程序按鈕沒有背景時,按鈕看起來像 ractanglemy_round_button<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android"    android:shape="ring">    <solid android:color="#FFFFFF" /></shape>怎么了?按鈕應(yīng)該看起來像戒指
查看完整描述

3 回答

?
大話西游666

TA貢獻1817條經(jīng)驗 獲得超14個贊

我建議您創(chuàng)建自定義視圖,它以圓形的形式呈現(xiàn)視圖,并根據(jù)我們從布局傳遞的寬度/高度。它更有活力。


我確實喜歡Son Truong建議的答案,但這似乎不是更通用,因為我們需要硬編碼尺寸寬度/高度。


第一步:創(chuàng)建主題style.xml


<declare-styleable name="CircleCompatTextView">

    <attr name="cctv_stroke_width" format="dimension" />

    <attr name="cctv_background_color" format="color" />

    <attr name="cctv_border_color" format="color" />

</declare-styleable>

第 2 步:創(chuàng)建自定義視圖。


public class CircleCompatTextView extends AppCompatTextView {

    private final Paint paintCircle = new Paint();

    private final Paint paintStroke = new Paint();

    private final Resources resources;

    private int strokeWidth;

    private int bgColor;

    private int borderColor;

    private int cxCy;


    public CircleCompatTextView(Context context, AttributeSet attrs) {

        super(context, attrs);

        resources = context.getResources();

        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CircleCompatTextView);

        strokeWidth = a.getDimensionPixelSize(R.styleable.CircleCompatTextView_cctv_stroke_width, 1);

        bgColor = a.getColor(R.styleable.CircleCompatTextView_cctv_background_color, resources.getColor(android.R.color.transparent));

        borderColor = a.getColor(R.styleable.CircleCompatTextView_cctv_border_color, resources.getColor(android.R.color.background_dark));

        a.recycle();

        init();

    }


    private void init() {

        paintCircle.setColor(bgColor);

        paintCircle.setFlags(Paint.ANTI_ALIAS_FLAG);

        paintStroke.setColor(borderColor);

        paintStroke.setStyle(Paint.Style.STROKE);

        paintStroke.setStrokeWidth(strokeWidth);

        paintStroke.setFlags(Paint.ANTI_ALIAS_FLAG);

    }



    @Override

    public void draw(Canvas canvas) {

        canvas.drawCircle(cxCy, cxCy, cxCy - strokeWidth / 2, paintStroke);

        canvas.drawCircle(cxCy, cxCy, cxCy - strokeWidth / 2, paintCircle);

        super.draw(canvas);

    }


    @Override

    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

        super.onMeasure(widthMeasureSpec, heightMeasureSpec);

        int width = getMeasuredWidth();

        int height = getMeasuredHeight();

        int size = ((height > width) ? height : width);

        cxCy = size / 2;

        setMeasuredDimension(size, size);

    }

}

第三步:自定義視圖的使用


<CircleCompatTextView

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:gravity="center|center_vertical"

        android:padding="16dp"

        android:textAlignment="center"

        app:cctv_background_color="@android:color/transparent"

        app:cctv_border_color="@android:color/background_dark"

        app:cctv_stroke_width="2dp" />

這是輸出

http://img1.sycdn.imooc.com//6125eb390001086c01990358.jpg

查看完整回答
反對 回復(fù) 2021-08-25
  • 3 回答
  • 0 關(guān)注
  • 179 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號