自定义dialog样式
来源:互联网 发布:电脑拍照软件 编辑:程序博客网 时间:2024/05/18 00:15
最近一直在赶项目很久没有来写文字了,项目中的一个视频播放做了足足一周多,还没有完全弄明白,好在功能已经实现可以播放了,今天就用先不做视频的总结。项目中很多判断都弹出了对话框,传统的对话框样式太丑,入不了我们UI的眼,满足不了需求,所以用到了自定义dialog,今天来总结dialog。
首先在网上搜了一下,网上有很多很多资料,但是大多数都写的很复杂,自己综合一下各家所长,做了一个最简单的demo
代码如下:
import android.app.Dialog;import android.content.Context;import android.os.Bundle;import android.view.LayoutInflater;import android.view.View;import android.widget.TextView;/** * Created by JLL on 2016/10/26. */public class MyDialog extends Dialog { private static View view; private TextView tv_finish ,mMessage ; Context mContext; public MyDialog (Context context){ super(context); mContext = context; } public MyDialog(Context context, int theme) { super(context, theme); mContext = context; } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LayoutInflater inflater = (LayoutInflater) mContext .getSystemService(Context.LAYOUT_INFLATER_SERVICE); view = inflater.inflate(R.layout.custom_dialog, null); this.setContentView(view); tv_finish = (TextView) findViewById(R.id.tv_finish); mMessage = (TextView) findViewById(R.id.tv_message1); mMessage.setText("该功能暂未对个人用户开放" + "\n" + "敬请期待!"); }}//自定义dialog布局文件
//MainActivity中只有一个简单的按钮,点击按钮弹出对话框
“`
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
private Button button;
@Overrideprotected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); button = (Button)findViewById(R.id.button); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final MyDialog dialog = new MyDialog(MainActivity.this,R.style.dialog);
// TextView message = (TextView) dialog.findViewById(R.id.tv_message1);
//
// message.setText(“caaaaaa”);
dialog.show();
View cancle = dialog.findViewById(R.id.tv_finish); TextView message = (TextView) dialog.findViewById(R.id.tv_message1); message.setText("23456");
//
cancle.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
//
Window window = dialog.getWindow();
WindowManager.LayoutParams lp = window.getAttributes();
lp.gravity = Gravity.CENTER;
lp.width =200;//宽高可设置具体大小
lp.height = 100;
dialog.getWindow().setAttributes(lp);
}
});
}
}
最后还要自定义样式文件value–>stysles中写
- Android-自定义Dialog样式
- Android 自定义Dialog样式
- Android dialog自定义样式
- 自定义dialog样式
- Android自定义Dialog样式
- 自定义Dialog样式
- Android 自定义Dialog样式
- 自定义dialog样式
- android自定义dialog样式
- 自定义dialog样式
- 自定义dialog的样式
- dialog 样式自定义详解
- android-自定义Dialog样式
- 自定义dialog样式
- 自定义Dialog样式
- android自定义Dialog样式
- 自定义dialog布局样式
- 自定义Dialog(自定义button样式)
- Intent传递数据时,可以传递哪些类型数据?
- ORACLE11g ORA-12514: TNS: 监听程序当前无法识别连接描述符中请求的服务
- 抽象建模能力-面试题44-扑克牌的顺子
- 指针变量初始化
- android 特卖列表倒计时卡顿问题
- 自定义dialog样式
- 设计模式(20)-中介者模式
- 洛谷 P1272 重建道路
- 第九周项目2-对称矩阵压缩存储的实现与应用(2)
- codechef minxor
- 棋盘覆盖算法
- BP神经网络
- Codeforce 543A(递推优化)
- html知识点概要(一)