qimi
V2EX  ›  Android

android 继承 AppCompatButton 来自定义 Button

  •  
  •   qimi · Mar 25, 2020 · 13459 views
    This topic created in 2267 days ago, the information mentioned may be changed or developed.

    代码如下:

    public class MyButton extends AppCompatButton {
        ...........
    
        @Override
        protected void onDraw(Canvas canvas) {
            // 这里留空
        }
    }
    

    XML 的定义:

    <com.example.qimi.MyButton
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_marginTop="50dp"
        android:layout_marginLeft="50dp"
        android:stateListAnimator="@null"/>
    

    为什么 onDraw()留空了,还会有灰色的按钮背景和点击波浪效果呢? 求解答...

    2 replies    2020-03-25 22:52:50 +08:00
    dozeboy
        1
    dozeboy  
       Mar 25, 2020   ❤️ 1
    View 的 draw() 方法里绘制的
    qimi
        2
    qimi  
    OP
       Mar 25, 2020   ❤️ 1
    @dozeboy 哦哦,一直以为只有 onDraw 绘制图像,谢谢
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   919 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 45ms · UTC 20:43 · PVG 04:43 · LAX 13:43 · JFK 16:43
    ♥ Do have faith in what you're doing.