博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Android自定义UI
阅读量:4560 次
发布时间:2019-06-08

本文共 2884 字,大约阅读时间需要 9 分钟。

 

Android setting中设置启动wifi,ethernet,bluetooth时需要的一种UI :

自定义UI类:

package com.example.androidinflateuidemo1;import android.content.Context;import android.util.AttributeSet;import android.view.LayoutInflater;import android.view.View;import android.widget.CompoundButton;import android.widget.CompoundButton.OnCheckedChangeListener;import android.widget.RelativeLayout;import android.widget.Switch;import android.widget.TextView;import android.widget.Toast;public class Custome_Component extends RelativeLayout{    private Context mContext;    private TextView mTitle,mSummary;    private Switch mSwitch;        public Custome_Component(Context context) {        super(context);        // TODO Auto-generated constructor stub    }    public Custome_Component(Context context, AttributeSet attrs, int defStyle) {        super(context, attrs, defStyle);        // TODO Auto-generated constructor stub    }    public Custome_Component(Context context, AttributeSet attrs) {        super(context, attrs);        // TODO Auto-generated constructor stub        mContext=context;        LayoutInflater layoutInflater=LayoutInflater.from(context);        final View mView=layoutInflater.inflate(R.layout.customeui, this);        mSwitch=(Switch)mView.findViewById(R.id.switch1);        mTitle=(TextView)mView.findViewById(R.id.textView1);        mSummary=(TextView)mView.findViewById(R.id.textView2);        mSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener(){            @Override            public void onCheckedChanged(CompoundButton arg0, boolean arg1) {                // TODO Auto-generated method stub                Toast.makeText(mContext, "switch", Toast.LENGTH_SHORT).show();            }                    });    }        public void setTitle(String title){        mTitle.setText(title);    }        public void setSummary(String summary){        mTitle.setText(summary);    }}

 

对应的XML:下面的不是手工写的,直接用布局器拖放的

主程序:

package com.example.androidinflateuidemo1;import android.os.Bundle;import android.app.Activity;import android.view.Menu;public class MainActivity extends Activity {    private com.example.androidinflateuidemo1.Custome_Component mCustomeUI;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        mCustomeUI=(com.example.androidinflateuidemo1.Custome_Component)this.findViewById(R.id.custome);        mCustomeUI.setTitle("customeui title");        mCustomeUI.setSummary("customeui summary");            }    @Override    public boolean onCreateOptionsMenu(Menu menu) {        // Inflate the menu; this adds items to the action bar if it is present.        getMenuInflater().inflate(R.menu.main, menu);        return true;    }    }

运行结果:

转载于:https://www.cnblogs.com/MMLoveMeMM/articles/3373246.html

你可能感兴趣的文章
web service 使用多态(转载)
查看>>
23醒
查看>>
Google Hack的一些整理
查看>>
[贪心] JZOJ P3757 随机生成器
查看>>
Codeforces Round #370 (Div. 2)(简单逻辑,比较水)
查看>>
ppt转换为html格式 抄的别人的 但是改成了web版 比较简陋
查看>>
操作系统进程调度算法
查看>>
less与sass的区别点
查看>>
event.keycode值大全
查看>>
array and ram
查看>>
工作笔记——禁用浏览器的返回按钮
查看>>
免费获得盛大网盘EverBox125G容量方法
查看>>
如何用spidermonkey在python里调用javascript代码
查看>>
2016级算法第一次练习赛-A.群鸦的盛宴
查看>>
浅谈深度学习和本体间的关系
查看>>
js下载文件
查看>>
python 中的高级函数filter()
查看>>
vim配置
查看>>
python创建系统时间字符串
查看>>
服务器上产看报错的日志的方法
查看>>