如何给Android中的按钮添加图片功能
2017-02-22 09:26
651 查看
在layout中建一个my_login.xml文件 代码如下
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:Android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center" android:background="@drawable/app_icon" android:orientation="vertical" > <Button android:id="@+id/startOrder_btn" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/apply" android:textSize="25sp" > </Button> <Button android:id="@+id/managerOrder_btn" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/apply" android:textSize="25sp" > </Button> </LinearLayout> -------------------------------------------------------------------------------------------------------------------------------------------- 在drawable-xxhdpi中添加图片 --------------------------------------------------------------------------------------------------------------------------------------------
在Mainactivity中添加如下代码:
LayoutInflater inflater = LayoutInflater.from(mMainActivity); View layout=inflater.inflate(R.layout.my_login,null); ContextThemeWrapper contextThemeWrapper = new ContextThemeWrapper(MainActivity.this, 2131099656); AlertDialog.Builder builder =new AlertDialog.Builder(contextThemeWrapper); builder.setView(layout); builder.setCancelable(false); builder.create().show(); Button startOrder_btn=(Button) layout.findViewById(R.id.startOrder_btn); Button managerOrder_btn=(Button) layout.findViewById(R.id.managerOrder_btn); startOrder_btn.setOnClickListener(new OnClickListener(){ public void onClick(View v) { //加上你要实现的代码 YSDKApi.login(ePlatform.QQ); } }); managerOrder_btn.setOnClickListener(new OnClickListener(){ public void onClick(View v) {//加上你要实现的代码 YSDKApi.login(ePlatform.WX); } });
以上所述是小编给大家介绍的给Android中的按钮添加图片功能,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!
您可能感兴趣的文章:
相关文章推荐
- 如何在Android平板电脑POWER按钮菜单中添加休眠功能
- Android中,如何实现在图片上添加返回功能
- 如何在Android平板电脑POWER按钮菜单中添加休眠功能
- 在Android 中调用选择图片、视频、添加音频、录音、拍摄视频、拍照等其他的功能
- 在Android 中调用选择图片、视频、添加音频、录音、拍摄视频、拍照等其他的功能
- sharepoint 2010 如何在Ribbon区添加功能按钮
- 如何给对话框添加背景图片及图片按钮CBUttonST
- Android如何添加系统长按键功能
- 实例讲解Android中如何实现图片的异步加载功能
- 实例讲解Android中如何实现图片的异步加载功能
- Android系统移植与调试之------->如何修改Android设备添加重启、飞行模式、静音模式等功能(一)
- android 中如何添加新的键值,实现更多功能
- android 如何给图片添加水印
- Android基础---WebView添加基本的放大缩小功能以及为图片添加放大缩小功能
- 实例讲解Android中如何实现图片的异步加载功能
- 黄聪:如何在wordpress任何一个页面调用“插入图片”按钮,实现上传图片功能
- Android 如何实现分享图片功能
- 在Android 中调用选择图片、视频、添加音频、录音、拍摄视频、拍照等其他的功能
- Android开发_如何设置按钮背景透明与半透明_图片背景透明