android自定义对话框怎么设置弧度
1个回答
2016-10-19
展开全部
我想你想要实现圆角的对话框,可以参考如下:
package com.example.jjy.myapplication;
import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
/**
* Created by jjy on 16-5-15.
*/
public class MyDialog extends Dialog{
private Button positiveButton, negativeButton;
private TextView contenttv;
public MyDialog(Context context) {
super(context,R.style.mydialog);
View view = LayoutInflater.from(getContext()).inflate(R.layout.mydialoglayout, null); //通过LayoutInflater获取布局
contenttv = (TextView) view.findViewById(R.id.title);
positiveButton = (Button) view.findViewById(R.id.acceptbtn);
negativeButton = (Button) view.findViewById(R.id.refusebtn);
setContentView(view); //设置view
}
//设置内容
public void setContent(String content) {
contenttv.setText(content);
}
//确定按钮监听
public void setOnPositiveListener(View.OnClickListener listener){
positiveButton.setOnClickListener(listener);
}
//否定按钮监听
public void setOnNegativeListener(View.OnClickListener listener){
negativeButton.setOnClickListener(listener);
}
}
R.style.mydialog 对话框属性在 values/styles.xml中设置:
[html] view plain copy
<resources>
<style name="mydialog" parent="android:style/Theme.Dialog">
<!-- 背景透明 -->
<item name="android:windowBackground">@android:color/transparent</item>
<!-- 没有标题 -->
<item name="android:windowNoTitle">true</item>
<!-- 背景模糊 -->
<item name="android:backgroundDimEnabled">true</item>
</style>
</resources>
package com.example.jjy.myapplication;
import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
/**
* Created by jjy on 16-5-15.
*/
public class MyDialog extends Dialog{
private Button positiveButton, negativeButton;
private TextView contenttv;
public MyDialog(Context context) {
super(context,R.style.mydialog);
View view = LayoutInflater.from(getContext()).inflate(R.layout.mydialoglayout, null); //通过LayoutInflater获取布局
contenttv = (TextView) view.findViewById(R.id.title);
positiveButton = (Button) view.findViewById(R.id.acceptbtn);
negativeButton = (Button) view.findViewById(R.id.refusebtn);
setContentView(view); //设置view
}
//设置内容
public void setContent(String content) {
contenttv.setText(content);
}
//确定按钮监听
public void setOnPositiveListener(View.OnClickListener listener){
positiveButton.setOnClickListener(listener);
}
//否定按钮监听
public void setOnNegativeListener(View.OnClickListener listener){
negativeButton.setOnClickListener(listener);
}
}
R.style.mydialog 对话框属性在 values/styles.xml中设置:
[html] view plain copy
<resources>
<style name="mydialog" parent="android:style/Theme.Dialog">
<!-- 背景透明 -->
<item name="android:windowBackground">@android:color/transparent</item>
<!-- 没有标题 -->
<item name="android:windowNoTitle">true</item>
<!-- 背景模糊 -->
<item name="android:backgroundDimEnabled">true</item>
</style>
</resources>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |