1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<
shape
xmlns:android
=
"http://schemas.android.com/apk/res/android"
android:shape=["rectangle" | "oval" | "line" | "ring"] >
<
corners
android:radius
=
"integer"
android:topLeftRadius
=
"integer"
android:topRightRadius
=
"integer"
android:bottomLeftRadius
=
"integer"
android:bottomRightRadius
=
"integer"
/>
<
gradient
android:angle
=
"integer"
android:centerX
=
"integer"
android:centerY
=
"integer"
android:centerColor
=
"integer"
android:endColor
=
"color"
android:gradientRadius
=
"integer"
android:startColor
=
"color"
android:type=["linear" | "radial" | "sweep"]
android:useLevel=["true" | "false"] />
<
padding
android:left
=
"integer"
android:top
=
"integer"
android:right
=
"integer"
android:bottom
=
"integer"
/>
<
size
android:width
=
"integer"
android:height
=
"integer"
/>
<
solid
android:color
=
"color"
/>
<
stroke
android:width
=
"integer"
android:color
=
"color"
android:dashWidth
=
"integer"
android:dashGap
=
"integer"
/>
</
shape
>
|
值 | 描述 |
rectangle | 长方形,默认值 |
oval | 椭圆 |
line | 水平直线,可以通过<stroke>标签来定义宽度 |
ring | 环形 |
值 | 描述 |
android:topRightRadius | 右上角 |
android:bottomLeftRadius | 右下角 |
android:topLeftRadius | 左上角 |
android:bottomRightRadius | 左下角 |
android:useLevel=["true" | "false"] />
值 | 描述 |
angle | 渐变角度。0是从左到右的,90是底部向顶部,必须是45的倍数,默认是0。 |
centerX | 以x位置为中心的渐变(0.0 -- 1.0)。 |
centerY | 以y位置为中心的渐变(0.0 -- 1.0)。 |
centerColor | 中心颜色 |
endColor | 结束颜色 |
gradientRadius | 径向渐变要指定半径值(android:type="radial" .) |
startColor | 开始颜色 |
type | |
useLevel | 设置资源管理的画板(不是很懂。。。) |
值 | 描述 |
width | 描边的宽度 |
color | 描边的颜色 |
dashWidth | 一个虚线"-"的宽度 |
dashGap | 一个虚线"-"的隔开距离 |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
<?
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
=
"wrap_content"
android:background
=
"@android:color/transparent"
android:orientation
=
"vertical"
>
<
LinearLayout
android:layout_width
=
"250dp"
android:layout_height
=
"wrap_content"
android:background
=
"@drawable/fragment_logout_button_backgroud_normal"
android:orientation
=
"vertical"
>
<
LinearLayout
android:layout_width
=
"fill_parent"
android:layout_height
=
"100dp"
android:orientation
=
"vertical"
>
<
TextView
android:id
=
"@+id/oneBtnInfo"
android:layout_width
=
"fill_parent"
android:layout_height
=
"40dp"
android:layout_margin
=
"2dp"
android:background
=
"@drawable/exit_bg"
android:gravity
=
"center"
android:text
=
"提示信息"
android:textColor
=
"#fff"
android:textSize
=
"20sp"
/>
<
TextView
android:id
=
"@+id/tishiInfo"
android:layout_width
=
"fill_parent"
android:layout_height
=
"wrap_content"
android:layout_marginTop
=
"20dp"
android:gravity
=
"center"
android:text
=
"确定要退出?"
android:textColor
=
"#000"
android:textSize
=
"18sp"
/>
</
LinearLayout
>
<
LinearLayout
android:layout_width
=
"fill_parent"
android:layout_height
=
"50dp"
android:layout_margin
=
"2dp"
android:background
=
"@color/gray_light"
android:gravity
=
"center"
android:orientation
=
"horizontal"
android:padding
=
"5dp"
>
<
Button
android:id
=
"@+id/exit_btn"
android:layout_width
=
"fill_parent"
android:layout_height
=
"35dp"
android:layout_margin
=
"5dp"
android:layout_weight
=
"1"
android:background
=
"@drawable/fragment_logout_button_selector"
android:text
=
"确定"
android:textColor
=
"@color/black"
/>
<
Button
android:id
=
"@+id/cancel_btn"
android:layout_width
=
"fill_parent"
android:layout_height
=
"35dp"
android:layout_margin
=
"5dp"
android:layout_weight
=
"1"
android:background
=
"@drawable/fragment_logout_button_selector"
android:text
=
"取消"
android:textColor
=
"@color/black"
/>
</
LinearLayout
>
</
LinearLayout
>
</
LinearLayout
>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<
shape
xmlns:android
=
"http://schemas.android.com/apk/res/android"
>
<
gradient
android:angle
=
"270"
android:centerColor
=
"@color/blue"
android:endColor
=
"@color/blue"
android:startColor
=
"@color/blue"
android:type
=
"linear"
/>
<
stroke
android:width
=
"0.5dp"
android:color
=
"@color/blue"
/>
<
corners
android:radius
=
"2dp"
android:topLeftRadius
=
"5dp"
android:topRightRadius
=
"5dp"
android:bottomLeftRadius
=
"0dp"
android:bottomRightRadius
=
"0dp"
/>
</
shape
>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
package
com.zhf.android_dialog_shape;
import
com.zhf.android_dialog_shape_theme.R;
import
android.os.Bundle;
import
android.app.Activity;
import
android.app.AlertDialog;
import
android.view.View;
import
android.view.View.OnClickListener;
import
android.view.Window;
import
android.widget.Button;
/**
* 测试自定义的Dialog(使用到了Shape Drawable)
* @author ZHF
*
*/
public
class
MainActivity
extends
Activity {
private
AlertDialog alertDialog;
private
Button button;
@Override
protected
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button)
this
.findViewById(R.id.button);
button.setOnClickListener(
new
OnClickListener() {
@Override
public
void
onClick(View v) {
loadExitDialog();
}
});
}
/**弹出自定义对话框**/
private
void
loadExitDialog() {
alertDialog =
new
AlertDialog.Builder(
this
).create();
alertDialog.show();
Window window = alertDialog.getWindow();
window.setContentView(R.layout.exit_dialog);
Button exit_btn = (Button) window.findViewById(R.id.exit_btn);
Button cancel_btn = (Button) window.findViewById(R.id.cancel_btn);
exit_btn.setOnClickListener(
new
OnClickListener() {
@Override
public
void
onClick(View v) {
finish();
}
});
cancel_btn.setOnClickListener(
new
OnClickListener() {
@Override
public
void
onClick(View v) {
alertDialog.dismiss();
}
});
}
}
|