Skip to content

Commit 9e5c7c0

Browse files
committed
custom cancel text
1 parent 8437f8a commit 9e5c7c0

File tree

8 files changed

+43
-18
lines changed

8 files changed

+43
-18
lines changed

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ allprojects {
2222

2323
```
2424
dependencies {
25-
compile 'com.github.fccaikai:BottomMenuTutorial:1.0.1'
25+
compile 'com.github.fccaikai:BottomMenuTutorial:1.0.2'
2626
}
2727
```
2828

@@ -47,20 +47,27 @@ dependencies {
4747
<dependency>
4848
<groupId>com.github.fccaikai</groupId>
4949
<artifactId>BottomMenuTutorial</artifactId>
50-
<version>1.0.1</version>
50+
<version>1.0.2</version>
5151
</dependency>
5252
```
5353

5454
### Usage
5555

5656
```
5757
BottomDialog dialog = BottomDialog.newInstance("title",new String[]{"item1","item2"});
58-
dialog.show(getChildFragmentManager(),"dialog");
59-
//add item click listener
60-
dialog.setListener(new BottomDialog.OnClickListener() {
61-
@Override
62-
public void click(int position) {
63-
Toast.makeText(getContext(), "" + position, Toast.LENGTH_LONG).show();
64-
}
58+
/**
59+
*
60+
* BottomDialog dialog = BottomDialog.newInstance("titleText","cancelText",new String[]{"item1","item2"});
61+
*
62+
* use public static BottomDialog newInstance(String titleText,String cancelText, String[] items)
63+
* set cancel text
64+
*/
65+
dialog.show(getChildFragmentManager(),"dialog");
66+
//add item click listener
67+
dialog.setListener(new BottomDialog.OnClickListener() {
68+
@Override
69+
public void click(int position) {
70+
Toast.makeText(getContext(), "" + position, Toast.LENGTH_LONG).show();
71+
}
6572
});
6673
```

app/src/main/java/com/kcode/bottommenututorial/MainFragment.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,17 @@ public void onClick(View view) {
5858

5959
public void showDialogFragment(){
6060
Log.i(TAG,"showDialogFragment");
61-
// BottomDialog bottomDialog = BottomDialog.newInstance();
62-
// bottomDialog.show(getChildFragmentManager(),BottomDialog.class.getSimpleName());
6361

6462
BottomDialog dialog = BottomDialog.newInstance("导航到这里去",new String[]{"高德地图","百度地图"});
63+
64+
/**
65+
*
66+
* BottomDialog dialog = BottomDialog.newInstance("titleText","cancelText",new String[]{"item1","item2"});
67+
*
68+
* use public static BottomDialog newInstance(String titleText,String cancelText, String[] items)
69+
* set cancel text
70+
*/
71+
6572
dialog.show(getChildFragmentManager(),"dialog");
6673
dialog.setListener(new BottomDialog.OnClickListener() {
6774
@Override

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
<string name="show_bottom_sheet">show bottom sheet</string>
55
<string name="hide_bottom_sheet_dialog">hide bottom sheet dialog</string>
66
<string name="show_bottom_sheet_dialog">show bottom sheet dialog</string>
7+
<string name="bottom_dialog_lib_cancel">取消啊</string>
78
</resources>

bottomlib/src/main/AndroidManifest.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
>
55

66
<application android:allowBackup="true"
7-
android:label="@string/app_name"
87
android:supportsRtl="true"
98
>
109

bottomlib/src/main/java/com/kcode/bottomlib/BottomDialog.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,23 @@
2727

2828
public class BottomDialog extends DialogFragment {
2929

30-
public static BottomDialog newInstance(String title, String[] items) {
30+
public static BottomDialog newInstance(String titleText, String[] items) {
31+
return newInstance(titleText,null,items);
32+
}
33+
34+
public static BottomDialog newInstance(String titleText,String cancelText, String[] items) {
3135

3236
Bundle args = new Bundle();
33-
args.putString("title", title);
37+
args.putString("title", titleText);
38+
args.putString("cancel",cancelText);
3439
args.putStringArray("items", items);
3540
BottomDialog fragment = new BottomDialog();
3641
fragment.setArguments(args);
3742
return fragment;
3843
}
3944

4045
private String mTitle;
46+
private String mCancel;
4147
private String[] items;
4248
private View mRootView;
4349
private OnClickListener mListener;
@@ -101,6 +107,7 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
101107

102108

103109
Button cancel = (Button) view.findViewById(R.id.cancel);
110+
cancel.setText(mCancel);
104111
cancel.setOnClickListener(new View.OnClickListener() {
105112
@Override
106113
public void onClick(View v) {
@@ -112,6 +119,10 @@ public void onClick(View v) {
112119
private void initData() {
113120
mTitle = getArguments().getString("title");
114121
items = getArguments().getStringArray("items");
122+
mCancel = getArguments().getString("cancel");
123+
if (TextUtils.isEmpty(mCancel)) {
124+
mCancel = getResources().getString(R.string.bottom_dialog_lib_cancel);
125+
}
115126
}
116127

117128
@Override

bottomlib/src/main/res/layout/bottom_lib_layout.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
android:layout_height="46dp"
4141
android:layout_marginTop="20dp"
4242
android:background="@drawable/seletcor_bottom_lib_button"
43-
android:text="@string/cancel"
43+
android:text="@string/bottom_dialog_lib_cancel"
4444
android:textSize="18sp"/>
4545

4646
</LinearLayout>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<resources>
2-
<string name="app_name">BottomLib</string>
3-
<string name="cancel">取消</string>
2+
<string name="cancel">@string/bottom_dialog_lib_cancel</string>
3+
<string name="bottom_dialog_lib_cancel">取消</string>
44
</resources>

0 commit comments

Comments
 (0)