android view 样式 style

xiaoxiao2021-02-28  75

 

对话框的样式:

AlertDialog.java

 

单选样式: setSingleChoiceItems 多选样式: setSingleChoiceItems

AlertController.AlertParams

 

 

 

 

private void createListView(final AlertController dialog) {                 if (mIsSingleChoice) {                     layout = dialog.mSingleChoiceItemLayout;                 } else {                     layout = dialog.mListItemLayout;                 }                 if (mCursor != null) {                     adapter = new SimpleCursorAdapter(mContext, layout, mCursor,                             new String[] { mLabelColumn }, new int[] { R.id.text1 }) { mSingleChoiceItemLayout;                 } else {                     layout = dialog.mListItemLayout;                 }                 if (mCursor != null) {                     adapter = new SimpleCursorAdapter(mContext, layout, mCursor,                             new String[] { mLabelColumn }, new int[] { R.id.text1 }) {

AlertController

 

 

public AlertController(Context context, DialogInterface di, Window window) { mContext = context; mDialogInterface = di; mWindow = window; mHandler = new ButtonHandler(di); final TypedArray a = context.obtainStyledAttributes(null, R.styleable.AlertDialog, R.attr.alertDialogStyle, 0); mAlertDialogLayout = a.getResourceId( R.styleable.AlertDialog_layout, R.layout.alert_dialog); mButtonPanelSideLayout = a.getResourceId( R.styleable.AlertDialog_buttonPanelSideLayout, 0); mListLayout = a.getResourceId( R.styleable.AlertDialog_listLayout, R.layout.select_dialog); mMultiChoiceItemLayout = a.getResourceId( R.styleable.AlertDialog_multiChoiceItemLayout, R.layout.select_dialog_multichoice); mSingleChoiceItemLayout = a.getResourceId( R.styleable.AlertDialog_singleChoiceItemLayout, R.layout.select_dialog_singlechoice); mListItemLayout = a.getResourceId( R.styleable.AlertDialog_listItemLayout, R.layout.select_dialog_item); mShowTitle = a.getBoolean(R.styleable.AlertDialog_showTitle, true); a.recycle(); /* We use a custom title so never request a window title */ window.requestFeature(Window.FEATURE_NO_TITLE); } mSingleChoiceItemLayout = a.getResourceId( R.styleable.AlertDialog_singleChoiceItemLayout, R.layout.select_dialog_singlechoice); mListItemLayout = a.getResourceId( R.styleable.AlertDialog_listItemLayout, R.layout.select_dialog_item); mShowTitle = a.getBoolean(R.styleable.AlertDialog_showTitle, true); a.recycle(); /* We use a custom title so never request a window title */ window.requestFeature(Window.FEATURE_NO_TITLE); }

select_dialog_singlechoice.xml

 

 

<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/text1" android:layout_width="match_parent" android:layout_height="wrap_content" android:minHeight="?android:attr/listPreferredItemHeight" android:textAppearance="?android:attr/textAppearanceLarge" android:textColor="?android:attr/textColorAlertDialogListItem" android:gravity="center_vertical" android:paddingStart="12dip" android:paddingEnd="7dip" android:checkMark="?android:attr/listChoiceIndicatorSingle" android:ellipsize="marquee" />

styles_holo.xml

 

 

    <style name="AlertDialog.Holo" parent="AlertDialog">         <item name="fullDark">@drawable/dialog_full_holo_dark</item>         <item name="topDark">@drawable/dialog_top_holo_dark</item>         <item name="centerDark">@drawable/dialog_middle_holo_dark</item>         <item name="bottomDark">@drawable/dialog_bottom_holo_dark</item>         <item name="fullBright">@drawable/dialog_full_holo_dark</item>         <item name="topBright">@drawable/dialog_top_holo_dark</item>         <item name="centerBright">@drawable/dialog_middle_holo_dark</item>         <item name="bottomBright">@drawable/dialog_bottom_holo_dark</item>         <item name="bottomMedium">@drawable/dialog_bottom_holo_dark</item>         <item name="centerMedium">@drawable/dialog_middle_holo_dark</item>         <item name="layout">@layout/alert_dialog_holo</item>         <item name="listLayout">@layout/select_dialog_holo</item>         <item name="progressLayout">@layout/progress_dialog_holo</item>         <item name="horizontalProgressLayout">@layout/alert_dialog_progress_holo</item>         <item name="listItemLayout">@layout/select_dialog_item_holo</item>         <item name="multiChoiceItemLayout">@layout/select_dialog_multichoice_holo</item> //多选         <item name="singleChoiceItemLayout">@layout/select_dialog_singlechoice_holo</item> //单选     </style> multiChoiceItemLayout">@layout/select_dialog_multichoice_holo</item> //多选         <item name="singleChoiceItemLayout">@layout/select_dialog_singlechoice_holo</item> //单选     </style>

select_dialog_singlechoice_holo.xml

 

 

<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@android:id/text1"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:minHeight="?android:attr/listPreferredItemHeightSmall"     android:textAppearance="?android:attr/textAppearanceMedium"     android:textColor="?android:attr/textColorAlertDialogListItem"     android:gravity="center_vertical"     android:paddingStart="16dip"     android:paddingEnd="16dip"     android:checkMark="?android:attr/listChoiceIndicatorSingle"     android:ellipsize="marquee" /> CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@android:id/text1"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:minHeight="?android:attr/listPreferredItemHeightSmall"     android:textAppearance="?android:attr/textAppearanceMedium"     android:textColor="?android:attr/textColorAlertDialogListItem"     android:gravity="center_vertical"     android:paddingStart="16dip"     android:paddingEnd="16dip"     android:checkMark="?android:attr/listChoiceIndicatorSingle"     android:ellipsize="marquee" />

CheckedTextView.java

public CheckedTextView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); final TypedArray a = context.obtainStyledAttributes( attrs, R.styleable.CheckedTextView, defStyleAttr, defStyleRes); final Drawable d = a.getDrawable(R.styleable.CheckedTextView_checkMark); if (d != null) { setCheckMarkDrawable(d); }CheckedTextView_checkMark); if (d != null) { setCheckMarkDrawable(d); }

themes_holo.xml

 

 

<item name="listChoiceIndicatorSingle">@drawable/btn_radio_holo_dark</item> <item name="listChoiceIndicatorSingle">@drawable/btn_radio_holo_light</item>

 

 

 

 

 

 

 

Android学习系列(40)--Android主题和样式之系统篇(下)

http://www.cnblogs.com/qianxudetianxia/p/3996020.html

 

关于CheckedTextView的思考

http://blog.sina.com.cn/s/blog_495c8c720101asjj.html

 

 

 

 

 

转载请注明原文地址: https://www.6miu.com/read-48404.html

最新回复(0)