Button—-button ImageButton—-图片button 共同拥有特征: 都能够作为一个button产生点击事件 不同点 1、 Button有text的属性。 ImageButton没有 2、 ImageButton有src属性。 Button没有 onClick事件 Button和ImageButton都有一个onClick事件 通过他们自身的.setOnClickListener(OnclickListener)方法加入点击事件 extends Activity implements OnClickListener { private TextView tv; private Button loginButton; private ImageButton ) findViewById(R.id.imageButton1); imgBt.setOnClickListener(this); } OnClickListener
后台实现的代码为 1 public class MainActivity extends Activity { 2 3 Button myButton; 4 ImageButton 2、ImageButton控件 ImageButton控件,可以作为button的另外一种扩展,他可以drawable中显示图标。 ImageButton控件的注册。 1 <ImageButton 2 android:id="@+id/imageButton1" 3 android:layout_width="60dp" 4 本文实现的主要是ImageButton控件的状态改变的时候,变换不同的图片。当鼠标单击的时候显示不同的图片。我们需要在drawable文件夹中加入一个xml文档。 <? android:drawable="@drawable/syicon_net_24" android:state_pressed="true"></item> </selector> 该文档用来注册imagebutton
image.png 目录 ImageButton(图像按钮) Android开发中除了使用Button按钮,还可以使用自带图标的按钮,即ImageButton。 Button与ImageButton的区别在于,Button生成的按钮上显示文字,而ImageButton上则显示图片。 注意 为ImageButton按钮指定android:text属性没用,由于ImageButton的本质是ImageView,即使指定了该属性,图片按钮上也不会显示任何文字。 使用方式: <ImageButton android:id="@+id/recentralization" android:layout_width="wrap_content ZoomButton 基本类似于 ImageButton,只是 Android 默认提供了 btn_minus、btn_plus 两个 Drawable 资源。当然也可以自己指定图片资源。
此时还要搞第二步:须要对ImageButton设置背景属性android:background=”#00000000″。就实现了不规则button的效果了。
一、ImageButton 在Android开发中除了使用Button按钮,还可以使用自带图标的按钮,即ImageButton。 Button与ImageButton的区别在于,Button生成的按钮上显示文字,而ImageButton上则显示图片。 需要指出的是,为ImageButton按钮指定android:text属性没用,由于ImageButton的本质是ImageView,即使指定了该属性,图片按钮上也不会显示任何文字。 接下来通过一个简单的示例程序来学习ImageButton的使用用法。 到此,这两个Button子组件ImageButton和ZoomButton已经学习完成,你都掌握了吗?
通过本节课可以学习到的内容: Button的用法 Button的样式 ImageButton的用法 点击事件的写法(之前已经讲过,不知还会否?) 获得焦点时的图片背景--> <item android:state_focused="true" android:drawable="@drawable/image6" /> </selector> ImageButton 的用法 <ImageButton android:onClick="btnClicked" android:id="@+id/imagebtn" android:layout_width=" layout_height="wrap_content" android:src="@mipmap/ic_launcher" /> android:src="@mipmap/ic_launcher"用来设定ImageButton 效果Gif 下课 这一节课,我们主要学习了Button和Button的样式以及ImageButton的简单用法。
由于我这里UI提供的图片比较特殊,所以第一张和第二张的图片分别可以通过设置 matrix和center获取到 <ImageButton android:id="@+id/qq_login <ImageButton android:id="@+id/wx_login" android:layout_width="wrap_content" android 此处省略18分钟 ---- 终极方案,完美解决 <ImageButton android:id="@+id/qq_login" android:layout_width app:layout_constraintStart_toStartOf="parent" app:srcCompat="@drawable/login" /> <ImageButton app:layout_constraintStart_toEndOf="@+id/qq_login" app:srcCompat="@drawable/login" /> <ImageButton
imageButton31;//前进 ImageButton imageButton32;//后退 ImageButton imageButton33;//右转 ImageButton = (ImageButton) findViewById(R.id.imageButton31);//前进 imageButton32 = (ImageButton) findViewById (R.id.imageButton32);//后退 imageButton33 = (ImageButton) findViewById(R.id.imageButton33);//右转 imageButton31;//前进 ImageButton imageButton32;//后退 ImageButton imageButton33;//右转 ImageButton (R.id.imageButton32);//后退 imageButton33 = (ImageButton) findViewById(R.id.imageButton33);//右转
我们要实现上图中的效果,需要如下的操作: 1.从工具栏上的“Smobiler Components”拖动一个Signature控件和一个ImageButton控件到窗体界面上 ? 2.修改ImageButton的属性 a.BackColor属性 设置控件的背景色,将该属性设置为“128, 255, 128”,表示RGB颜色,如图1; b.BackColorAlpha属性 设置控件背景色透明度 d.ResourceID属性 设置按钮图标名称,将该属性设置为“Sc1”,如图4; e.Size属性 设置控件的宽度和高度,将该属性设置为(53, 21),如图5; 图1 图2 图3 图4 图5 e.ImageButton 的Click事件 VB: Private Sub ImageButton1_Click(sender As Object, e As EventArgs) Handles ImageButton1 .Click Signature1.GetSignature() End Sub C#: private void ImageButton1_Click(object sender
的开发平台,也许比Xamarin更方便 样式一 一、目标样式 我们要实现上图中的效果,需要如下的操作: 1.从工具栏上的“Smobiler Components”拖动一个LayoutDialog控件和一个ImageButton LayoutDialog控件的属性 a.Layout属性 新建MobileForm项,命名为MessageShow,如图1; 设置弹出框布局,绑定新建的窗体MessageShow,如图2; 图1 图2 3.ImageButton 的Click事件 VB: Private Sub imageButton1_Click(sender As Object, e As EventArgs)Handles imageButton1. Click layoutDialog1.Show(new MessageShow()) End Sub C#: private void imageButton1_Click(
,因为它是可以点击的,而ImageButton中未实现监听器,所以不能响应。 mweixin_image; 34 private ImageButton mfrd_image; 35 private ImageButton madd_image; 36 private ImageButton mset_image; 37 @Override 38 protected void onCreate(Bundle savedInstanceState 107 mweixin_image = (ImageButton) findViewById(R.id.id_tab_weixin_image); 108 madd_image = (ImageButton) findViewById(R.id.id_tab_add_image); 109 mfrd_image = (ImageButton
LinearLayout mTabFrd; private LinearLayout mTabAddress; private LinearLayout mTabSettings; private ImageButton mImgWeixin; private ImageButton mImgFrd; private ImageButton mImgAddress; private ImageButton mImgSettings R.id.id_tab_address); mTabSettings = (LinearLayout) findViewById(R.id.id_tab_settings); mImgWeixin = (ImageButton ) findViewById(R.id.id_tab_weixin_img); mImgFrd = (ImageButton) findViewById(R.id.id_tab_frd_img); mImgAddress = (ImageButton) findViewById(R.id.id_tab_address_img); mImgSettings = (ImageButton) findViewById(R.id.id_tab_settings_img
layout_height="wrap_content" android:layout_marginTop="@dimen/eight_dp"> <ImageButton </RelativeLayout> </LinearLayout> </LinearLayout> </ScrollView> 实现 LinkedList<ImageButton > mAddList; mAddList.add(curView, btAdd); LinkedList<ImageButton> mDelList; mDelList.add(curView, btDel ); 这里我使用LinkedList<ImageButton>实例存储ImageButton, 就是为了让增删的时候方便一些. }); rl.addView(btAdd); mAddList.add(curView, btAdd); // ib_del ImageButton
private ImageButton mImg1; private ImageButton mImg2; private ImageButton mImg3; private ImageButton mImg4; //声明四个Tab分别对应的Fragment private Fragment mFrag1; private Fragment mFrag2 mImg1=(ImageButton)findViewById(R.id.id_tab_img1); mImg2=(ImageButton)findViewById(R.id.id_tab_img2 ); mImg3=(ImageButton)findViewById(R.id.id_tab_img3); mImg4=(ImageButton)findViewById =null){ transaction.hide(mFrag4); } } //将四个ImageButton置为灰色 private void
import org.eclipse.swt.events.MouseAdapter; /** * 透明背景图像按钮 * @author guyadong * */ public class ImageButton transparent 指定透明色,为null时没有透明色 * @param style * @wbp.parser.constructor */ public ImageButton , 0, 0, ImageButton.this.image.getBounds().width, ImageButton.this.image.getBounds (Composite, Image, RGB) */ public ImageButton(Composite parent, Image image) { this( canvas_1 = new ImageButton(shell, SWTResourceManager.getImage(TestApp.class, "/image/arrow_left.png"
android:layout_alignParentBottom="true" android:background="@drawable/bottom_bg"> <ImageButton > <ImageButton android:id="@+id/ib_change_view" android:layout_alignParentLeft="true > <ImageButton android:id="@+id/ib_change_view" android:layout_alignParentLeft="true > <ImageButton android:id="@+id/ib_change_category" android:layout_alignParentLeft 其中ImageButton的属性android:src如果设置的图片较大则全部显示,解决的办法是要么用android:background,要么干脆换成ImageView。
我们要实现上图中的效果,需要如下的操作: 从工具栏上的“Smobiler Components”拖动一个VoiceRecorder控件和一个ImageButton控件到窗体界面上 ? 修改ImageButton的属性 1.BackColor属性 设置控件的背景色,将该属性设置为“Gray”,如图1; ? 图 4 5.ImageButton的Click事件 VB: Private Sub ImageButton1_Click(sender As Object, e As EventArgs) Handles ImageButton1.Click VoiceRecorder1.GetRecorderAudio() End Sub 修改VoiceRecorder的属性
public class MainActivity extends AppCompatActivity implements View.OnClickListener{ private ImageButton weixin; private ImageButton contact; private ImageButton find; private ImageButton me; super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); weixin = (ImageButton ) findViewById(R.id.weixin1); contact = (ImageButton) findViewById(R.id.weixin2); find = (ImageButton) findViewById(R.id.weixin3); me = (ImageButton) findViewById(R.id.weixin4);
layout_marginRight="2px" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView> <ImageButton wrap_content" android:src="@drawable/main" android:background="@null" android:layout_marginRight="10px"> </ImageButton color/white" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView> <ImageButton android:layout_height="wrap_content" android:src="@drawable/main" android:background="@null" > </ImageButton
参考示例程序:ImageButton(ApiDemo=>Views=>ImageButton) 源代码:com/example/android/apis/view/ImageButton.java 图像按钮 ImageButton 扩展了 ImageView,它结合了图像和按钮的功能。 ImageButton 除了可以当作按钮来使用,其他方面和 ImageView 基本一致。 ImageButton 和 ImageView 的区别也仅在于外观和使用方式上,主要的图像设置方法和 ImageButton 中的一样。 事实上,ImageButton 除了在外观上表现成一个按钮的状态,其他方面和 ImageView 基本一样。