L-Dialogs, 在android中,一个复制新对话框的小型库

分享于 

7分钟阅读

GitHub

  繁體
A small library replicating the new dialogs in android L.
  • 源代码名称:L-Dialogs
  • 源代码网址:http://www.github.com/lewisjdeane/L-Dialogs
  • L-Dialogs源代码文档
  • L-Dialogs源代码下载
  • Git URL:
    git://www.github.com/lewisjdeane/L-Dialogs.git
    Git Clone代码到本地:
    git clone http://www.github.com/lewisjdeane/L-Dialogs
    Subversion代码到本地:
    $ svn co --depth empty http://www.github.com/lewisjdeane/L-Dialogs
    Checked out revision 1.
    $ cd repo
    $ svn up trunk
    
    对话框

    一个小型库,在android中复制新。

    "Screenshot 1"

    设置( Android Studio ):

    在这里下载 aar: https://www.dropbox.com/s/276bhapr2g50cak/ldialogs.aar?dl=0

    Maven 中央支持即将推出。

    你可以重命名 aar,然后将它的放在你的项目的libs目录中。

    进入你的build.gradle 并添加以下内容:

    
    
    
    
    dependencies {
    
    
     compile fileTree(dir: 'libs', include: ['*.jar'])
    
    
     compile 'uk.me.lewisdeane.ldialogs:RENAMED_FILE_NAME_HERE@aar'
    
    
    }
    
    
    
    repositories{
    
    
     flatDir{
    
    
     dirs 'libs'
    
    
     }
    
    
    }
    
    
    
    
    
    用法

    ##Normal 对话框

    现在你应该能够从一个java文件中访问类CustomDialog了。

    要创建一个新的CustomDialog,我们需要使用一个生成器,如下所示:

    
    
    
    
    // Create the builder with required paramaters - Context, Title, Positive Text
    
    
    CustomDialog.Builder builder = new CustomDialog.Builder(Context context, String title, String positiveText);
    
    
    
    // Now we can any of the following methods.
    
    
    builder.content(String content);
    
    
    builder.negativeText(String negativeText);
    
    
    builder.darkTheme(boolean isDark);
    
    
    builder.typeface(Typeface typeface);
    
    
    builder.titleTextSize(int size);
    
    
    builder.contentTextSize(int size);
    
    
    builder.buttonTextSize(int size);
    
    
    builder.titleAlignment(Alignment alignment); // Use either Alignment.LEFT, Alignment.CENTER or Alignment.RIGHT
    
    
    builder.titleColor(String hex); // int res, or int colorRes parameter versions available as well.
    
    
    builder.contentColor(String hex); // int res, or int colorRes parameter versions available as well.
    
    
    builder.positiveColor(String hex); // int res, or int colorRes parameter versions available as well.
    
    
    builder.negativeColor(String hex); // int res, or int colorRes parameter versions available as well.
    
    
    builder.positiveBackground(Drawable drawable); // int res parameter version also available.
    
    
    builder.rightToLeft(boolean rightToLeft); // Enables right to left positioning for languages that may require so.
    
    
    
    // Now we can build the dialog.
    
    
    CustomDialog customDialog = builder.build();
    
    
    
    // Show the dialog.
    
    
    customDialog.show();
    
    
    
    

    若要处理按钮单击,可以使用以下代码:

    
    
    
    
    customDialog.setClickListener(new CustomDialog.ClickListener() {
    
    
     @Override
    
    
     public void onConfirmClick() {
    
    
    
     }
    
    
    
     @Override
    
    
     public void onCancelClick() {
    
    
    
     }
    
    
     });
    
    
    
    

    如果要在对话框中设置自定义视图,可以使用下列方法。

    
    
    
    
    customDialog.setCustomView(View customView);
    
    
    
    

    然后执行onConfirmClick或者onCancelClick中自定义视图内容所需的操作。

    ##List 对话框

    要使用 CustomListDialog,我们需要再次使用生成器,这是按如下方式执行的:

    
    
    
    
    // Create list dialog with required parameters - context, title, and our array of items to fill the list.
    
    
    CustomListDialog.Builder builder = new CustomListDialog.Builder(Context context, String title, String[] items);
    
    
    
    // Now again we can use some extra methods on the builder to customise it more.
    
    
    builder.darkTheme(boolean isDark);
    
    
    builder.typeface(Typeface typeface);
    
    
    builder.titleAlignment(Alignment alignment); // Use either Alignment.LEFT, Alignment.CENTER or Alignment.RIGHT
    
    
    builder.itemAlignment(Alignment alignment); // Use either Alignment.LEFT, Alignment.CENTER or Alignment.RIGHT
    
    
    builder.titleColor(String hex); // int res, or int colorRes parameter versions available as well.
    
    
    builder.itemColor(String hex); // int res, or int colorRes parameter versions available as well.
    
    
    builder.titleTextSize(int size);
    
    
    builder.itemTextSize(int size);
    
    
    builder.rightToLeft(boolean rightToLeft); // Enables right to left positioning for languages that may require so.
    
    
    
    // Now we can build our dialog.
    
    
    CustomListDialog customListDialog = builder.build();
    
    
    
    // Finally we can show it.
    
    
    customListDialog.show();
    
    
    
    

    要接收对话框中的click事件,只需在customListDialog上使用以下方法:

    
    
    
    
    customListDialog.setListClickListener(new CustomListDialog.ListClickListener() {
    
    
     @Override
    
    
     public void onListItemSelected(int i, String[] strings, String s) {
    
    
     // i is the position clicked.
    
    
     // strings is the array of items in the list.
    
    
     // s is the item selected.
    
    
     }
    
    
     });
    
    
    
    

    若要添加listview选择器,请使用以下代码:

    
    
    
    
    StateListDrawable selector = new StateListDrawable();
    
    
    selector.addState(new int[]{android.R.attr.state_pressed}, new ColorDrawable(R.color.color1));
    
    
    selector.addState(new int[]{-android.R.attr.state_pressed}, new ColorDrawable(R.color.color2));
    
    
    
    // The important part:
    
    
    customListDialog.getListView().setSelector(selector);
    
    
    
    

    这里库将经常更新,享受 !


    rep  repl  DIA  android-l  对话框  dialogs  
    相关文章