如何给Android中的按钮添加图片功能
在layout中建一个my_login.xml文件代码如下
<?xmlversion="1.0"encoding="utf-8"?> <LinearLayoutxmlns: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中添加如下代码:
LayoutInflaterinflater=LayoutInflater.from(mMainActivity);
Viewlayout=inflater.inflate(R.layout.my_login,null);
ContextThemeWrappercontextThemeWrapper=newContextThemeWrapper(MainActivity.this,2131099656);
AlertDialog.Builderbuilder=newAlertDialog.Builder(contextThemeWrapper);
builder.setView(layout);
builder.setCancelable(false);
builder.create().show();
ButtonstartOrder_btn=(Button)layout.findViewById(R.id.startOrder_btn);
ButtonmanagerOrder_btn=(Button)layout.findViewById(R.id.managerOrder_btn);
startOrder_btn.setOnClickListener(newOnClickListener(){
publicvoidonClick(Viewv){
//加上你要实现的代码
YSDKApi.login(ePlatform.QQ);
}
});
managerOrder_btn.setOnClickListener(newOnClickListener(){
publicvoidonClick(Viewv){//加上你要实现的代码
YSDKApi.login(ePlatform.WX);
}
});
以上所述是小编给大家介绍的给Android中的按钮添加图片功能,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对毛票票网站的支持!
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下