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EhkAoCyQyAAAZYFEBgAoCyQyAEBZIJEBAMriw98AAFAOH/4HAADl8H/9hTTEBoSbsQAAAABJRU5ErkJggg==" alt="" />
2. 实现代码
package com.example.timetest; import android.content.Context;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView; public class ImageButton extends LinearLayout { private ImageView mImageView; private TextView mTextView; public ImageButton (
Context context , AttributeSet attrs ) { super ( context , attrs ); mImageView = new ImageView ( context );
mImageView.setImageResource ( R.drawable.add_tip );
mImageView.setPadding ( 0 , 0 , 5 , 0 );
mTextView = new TextView ( context );
mTextView.setText ( "添加提醒" );
setOrientation ( LinearLayout.HORIZONTAL );
addView ( mImageView );
addView ( mTextView ); } }
3. 使用的图片
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAMAAAC7IEhfAAAAh1BMVEX/goL/goL/goL/goL/goL/goL/goL/goL/goL/goL/goL/goL/goL/goL/goL/goL/goL/goL/goL/goL/goL/goL/goL/goL/goL/goL/////goL/goL/goL/goL/goL/goL/goL/goL/goL/goL/goL/goL/goL/goL/goL/goL/goL/goKcHLqoAAAALXRSTlMAAjd4rNLt+ByH4v8TlflW61cElwqzsZhZFf8e+uN50+w4WFqZBra0BRSI5O7ADc0xAAABA0lEQVQ4y42V6RaCIBBGR0RTJ8lCs8XM9s33f746tnEEZL6/3MMchuECoMZjPg/C0SgMuM88sCWKE1SSxJERG6cCexHpWOcmGRqSTXvYTKIlcqZyeYHWFLmy3xwHMv/vWeJgyi83RUcWn75kLjBcdqB24NXKWHxducFq/QJjdIMYv+ZgQwE3HjCkgMigpoE+cBrIYUsDt9DQwAaEsq7nP8N0kFyafBhye8gN31GvkDwU5DGDSLhB0ckldYPy/bga1+NqPgrau8ADUQDHnylOw0o5KZI627lLrursaq1eXnuG3JtFutCVe5O6muXNLPv7Q8Ue98j6L3is5kFbVW3A69738QSzTkFxawYzgQAAAABJRU5ErkJggg==" alt="" />
4. 使用自定义控件
<com.example.timetest.ImageButton
android:id="@+id/add"
android:layout_width="match_parent"
android:layout_height="40dp"
android:gravity="center" />
Ok 完成了