V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
qimi
V2EX  ›  Android

android 继承 AppCompatButton 来自定义 Button

  •  
  •   qimi · Mar 25, 2020 · 13359 views
    This topic created in 2227 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   ·   2418 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 55ms · UTC 11:06 · PVG 19:06 · LAX 04:06 · JFK 07:06
    ♥ Do have faith in what you're doing.