下面列出了android.widget.ListView#setCacheColorHint ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
protected View createView(LayoutInflater layoutInflater, ViewGroup viewGroup) {
// 不显示默认标题
getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
mCommonFrameLayout = new CommonFrameLayout(getContext());
mToolbar = mCommonFrameLayout.getTitleView();
mMoreButton = mToolbar.addMoreImageButton();
LinearLayout content = LayoutUtil.newCommonLayout(getContext());
mListView = new ListView(getContext());
mListView.setCacheColorHint(0x00000000);
mListView.setDividerHeight(0);
mListView.setLayoutParams(LayoutUtil.newMatchFrameLayoutParams());
content.addView(mListView);
mCommonFrameLayout.setContent(content);
return mCommonFrameLayout;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ListView lv = new ListView(mContext);
lv.setCacheColorHint(Color.TRANSPARENT);
lv.setFadingEdgeLength(0);
lv.setAdapter(new SimpleHomeAdapter(mContext, mItems));
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(mContext, mClasses[position]);
startActivity(intent);
}
});
setContentView(lv);
}
@SuppressWarnings("deprecation")
protected void showPreferences() {
ListView lv = getListView();
if (lv != null) {
lv.setBackgroundColor(this.getResources().getColor(R.color.bc_bg_color));
lv.setCacheColorHint(this.getResources().getColor(R.color.bc_bg_color));
lv.setSelector(R.drawable.setting_pref_item_background_selector);
ColorDrawable dividerDrawable = new ColorDrawable(this.getResources().getColor(R.color.bc_green_blue_color));
lv.setDivider(dividerDrawable);
lv.setDividerHeight(1);
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
addPreferencesFromResource(R.xml.preferences);
} else {
loadSettingsFragment();
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ListView lv = new ListView(mContext);
lv.setCacheColorHint(Color.TRANSPARENT);
lv.setFadingEdgeLength(0);
lv.setAdapter(new SimpleHomeAdapter(mContext, mItems));
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(mContext, mClasses[position]);
startActivity(intent);
}
});
setContentView(lv);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mDisplayMetrics = getResources().getDisplayMetrics();
ListView lv = new ListView(mContext);
lv.setCacheColorHint(Color.TRANSPARENT);
lv.setBackgroundColor(Color.WHITE);
lv.setFadingEdgeLength(0);
lv.setAdapter(new SimpleHomeAdapter());
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(mContext, mClazzs[position]);
startActivity(intent);
}
});
setContentView(lv);
}
/**
* 列表显示,显示列表屏蔽按钮
*/
private void initListView(ViewGroup viewRoot) {
listView = new ListView(context);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
layoutParams.setMargins(dp2px(15), dp2px(5), dp2px(15), dp2px(5));
listView.setLayoutParams(layoutParams);
listView.setCacheColorHint(Color.TRANSPARENT);
listView.setFadingEdgeLength(0);
listView.setVerticalScrollBarEnabled(false);
listView.setSelector(new ColorDrawable(Color.TRANSPARENT));
listView.setDivider(new ColorDrawable(Color.LTGRAY));
listView.setDividerHeight(dp2px(0.8f));
if (dialogAdapter == null) {
dialogAdapter = new ListDialogAdapter();
}
listView.setAdapter(dialogAdapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
dismiss();
if (listener != null) {
listener.click(false, position);
}
}
});
listView.setLayoutAnimation(getLayoutAnimation());
viewRoot.addView(listView);
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
//Current position should survive screen rotations.
if (savedInstanceState != null) {
mCategory = savedInstanceState.getInt("category");
mCurPosition = savedInstanceState.getInt("listPosition");
}
populateTitles(mCategory);
ListView lv = getListView();
lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
lv.setCacheColorHint(Color.TRANSPARENT);
lv.setOnItemLongClickListener(new OnItemLongClickListener() {
public boolean onItemLongClick(AdapterView<?> av, View v, int pos, long id) {
final String title = (String) ((TextView) v).getText();
// Set up clip data with the category||entry_id format.
final String textData = String.format("%d||%d", mCategory, pos);
ClipData data = ClipData.newPlainText(title, textData);
v.startDrag(data, new MyDragShadowBuilder(v), null, 0);
return true;
}
});
selectPosition(mCurPosition);
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
//Current position should survive screen rotations.
if (savedInstanceState != null) {
mCategory = savedInstanceState.getInt("category");
mCurPosition = savedInstanceState.getInt("listPosition");
}
populateTitles(mCategory);
ListView lv = getListView();
lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
lv.setCacheColorHint(Color.TRANSPARENT);
lv.setOnItemLongClickListener(new OnItemLongClickListener() {
@SuppressLint("DefaultLocale")
public boolean onItemLongClick(AdapterView<?> av, View v, int pos, long id) {
final String title = (String) ((TextView) v).getText();
// Set up clip data with the category||entry_id format.
final String textData = String.format("%d||%d", mCategory, pos);
ClipData data = ClipData.newPlainText(title, textData);
v.startDrag(data, new MyDragShadowBuilder(v), null, 0);
return true;
}
});
selectPosition(mCurPosition);
}
@Override
public View onCreateView() {
LinearLayout ll_container = new LinearLayout(mContext);
ll_container.setOrientation(LinearLayout.VERTICAL);
/** title */
mTvTitle = new TextView(mContext);
mTvTitle.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
mTvTitle.setSingleLine(true);
mTvTitle.setPadding(dp2px(18), dp2px(10), 0, dp2px(10));
ll_container.addView(mTvTitle);
/** listview */
mLv = new ListView(mContext);
mLv.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
mLv.setCacheColorHint(Color.TRANSPARENT);
mLv.setFadingEdgeLength(0);
mLv.setVerticalScrollBarEnabled(false);
mLv.setSelector(new ColorDrawable(Color.TRANSPARENT));
ll_container.addView(mLv);
return ll_container;
}
@Override
protected ListView createRefreshableView(Context context, AttributeSet attrs) {
ListView lv = createListView(context, attrs);
lv.setScrollingCacheEnabled(false);
lv.setFadingEdgeLength(0);
lv.setDivider(new ColorDrawable(Color.LTGRAY));
lv.setCacheColorHint(Color.TRANSPARENT);
// Set it to this so it can be used in ListActivity/ListFragment
lv.setId(android.R.id.list);
return lv;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
//Current position should survive screen rotations.
if (savedInstanceState != null) {
mCategory = savedInstanceState.getInt("category");
mCurPosition = savedInstanceState.getInt("listPosition");
}
populateTitles(mCategory);
ListView lv = getListView();
lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
lv.setCacheColorHint(Color.TRANSPARENT);
lv.setOnItemLongClickListener(new OnItemLongClickListener() {
public boolean onItemLongClick(AdapterView<?> av, View v, int pos, long id) {
final String title = (String) ((TextView) v).getText();
// Set up clip data with the category||entry_id format.
final String textData = String.format("%d||%d", mCategory, pos);
ClipData data = ClipData.newPlainText(title, textData);
v.startDrag(data, new MyDragShadowBuilder(v), null, 0);
return true;
}
});
selectPosition(mCurPosition);
}
private void willShowPopupWindow() {
int userCount = mListAdapter.getCount();
if (userCount > mRememberCount) {
userCount = mRememberCount;
}
int itemHeight = getResources().getDimensionPixelSize(R.dimen.remember_item_height);
mPopupWindowHeight = itemHeight * userCount + (userCount - 1);
if (pop == null) {
mCacheListView = new ListView(getContext());
mCacheListView.setCacheColorHint(0);
mCacheListView.setScrollingCacheEnabled(false);
mCacheListView.setFadingEdgeLength(0);
mCacheListView.setDivider(new ColorDrawable(Color.GRAY));
mCacheListView.setDividerHeight(1);
LayoutParams params = new LayoutParams(getWidth(), mPopupWindowHeight);
mCacheListView.setLayoutParams(params);
mCacheListWrapperLinearLayout = new LinearLayout(getContext());
mCacheListWrapperLinearLayout.setLayoutParams(params);
mCacheListWrapperLinearLayout.addView(mCacheListView);
pop = new SafePopupWindow(mCacheListWrapperLinearLayout, getWidth(), LayoutParams.WRAP_CONTENT);
mCacheListView.setAdapter(mListAdapter);
}
pop.setAnimationStyle(R.style.RememberEditTextPopupWindowAnim);
pop.showAsDropDown(this);
mListAdapter.notifyDataSetChanged();
mIconStatus = ICON_SHOW_DROP_UP;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 添加Activity到堆栈
AppManager.getAppManager().addActivity(this);
myApplication = (BaseApplication) getApplication();
// 设置显示Preferences
addPreferencesFromResource(R.xml.preferences);
// 获得SharedPreferences
mPreferences = PreferenceManager.getDefaultSharedPreferences(this);
ListView localListView = getListView();
localListView.setBackgroundColor(0);
localListView.setCacheColorHint(0);
((ViewGroup) localListView.getParent()).removeView(localListView);
ViewGroup localViewGroup = (ViewGroup) getLayoutInflater().inflate(
R.layout.setting_activity, null);
((ViewGroup) localViewGroup.findViewById(R.id.setting_content))
.addView(localListView, -1, -1);
setContentView(localViewGroup);
initView();
}
/**
* help to build ClassTableListView
* @param ctx
* @return
*/
public static ListView buildClassListView(Context ctx){
ListView classListView = new ListView(ctx);
classListView.setBackgroundColor(0);
classListView.setCacheColorHint(0);
classListView.setDividerHeight(0);
return classListView;
}
@Override
public View onCreateView() {
LinearLayout ll_container = new LinearLayout(mContext);
ll_container.setOrientation(LinearLayout.VERTICAL);
ll_container.setBackgroundColor(Color.TRANSPARENT);
/** title */
mTvTitle = new TextView(mContext);
mTvTitle.setGravity(Gravity.CENTER);
mTvTitle.setPadding(dp2px(10), dp2px(5), dp2px(10), dp2px(5));
LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
params.topMargin = dp2px(20);
ll_container.addView(mTvTitle, params);
/** title underline */
mVLineTitle = new View(mContext);
ll_container.addView(mVLineTitle);
/** listview */
mLv = new ListView(mContext);
mLv.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 1));
mLv.setCacheColorHint(Color.TRANSPARENT);
mLv.setFadingEdgeLength(0);
mLv.setVerticalScrollBarEnabled(false);
mLv.setSelector(new ColorDrawable(Color.TRANSPARENT));
ll_container.addView(mLv);
/** mCancel btn */
mTvCancel = new TextView(mContext);
mTvCancel.setGravity(Gravity.CENTER);
LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
lp.topMargin = dp2px(7);
lp.bottomMargin = dp2px(7);
mTvCancel.setLayoutParams(lp);
ll_container.addView(mTvCancel);
return ll_container;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
ListView lv = getListView();
//getListView().setSelector(R.drawable.transparent);
lv.setCacheColorHint(Color.TRANSPARENT);
// View management
View detailsFrame = getActivity().findViewById(R.id.details);
dualPane = detailsFrame != null && detailsFrame.getVisibility() == View.VISIBLE;
if (savedInstanceState != null) {
// Restore last state for checked position.
curCheckPosition = savedInstanceState.getLong(CURRENT_CHOICE, SipProfile.INVALID_ID);
//curCheckWizard = savedInstanceState.getString(CURRENT_WIZARD);
}
setListShown(false);
if(mAdapter == null) {
if(mHeaderView != null) {
lv.addHeaderView(mHeaderView , null, true);
}
mAdapter = new AccountsEditListAdapter(getActivity(), null);
mAdapter.setOnCheckedRowListener(this);
//getListView().setEmptyView(getActivity().findViewById(R.id.progress_container));
//getActivity().findViewById(android.R.id.empty).setVisibility(View.GONE);
setListAdapter(mAdapter);
registerForContextMenu(lv);
// Prepare the loader. Either re-connect with an existing one,
// or start a new one.
getLoaderManager().initLoader(0, null, this);
lv.setVerticalFadingEdgeEnabled(true);
}
if (dualPane) {
// In dual-pane mode, the list view highlights the selected item.
Log.d("lp", "dual pane mode");
lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
//lv.setVerticalScrollbarPosition(View.SCROLLBAR_POSITION_LEFT);
lv.setVerticalScrollBarEnabled(false);
lv.setFadingEdgeLength(50);
updateCheckedItem();
// Make sure our UI is in the correct state.
//showDetails(curCheckPosition, curCheckWizard);
}else {
//getListView().setVerticalScrollbarPosition(View.SCROLLBAR_POSITION_RIGHT);
lv.setVerticalScrollBarEnabled(true);
lv.setFadingEdgeLength(100);
}
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
ListView lv = getListView();
//getListView().setSelector(R.drawable.transparent);
lv.setCacheColorHint(Color.TRANSPARENT);
// View management
View detailsFrame = getActivity().findViewById(R.id.details);
dualPane = detailsFrame != null && detailsFrame.getVisibility() == View.VISIBLE;
if (savedInstanceState != null) {
// Restore last state for checked position.
curCheckFilterId = savedInstanceState.getLong(CURRENT_CHOICE, SipProfile.INVALID_ID);
//curCheckWizard = savedInstanceState.getString(CURRENT_WIZARD);
}
setListShown(false);
if(mAdapter == null) {
if(mHeaderView != null) {
lv.addHeaderView(mHeaderView , null, true);
}
mAdapter = new AccountFiltersListAdapter(getActivity(), null);
//getListView().setEmptyView(getActivity().findViewById(R.id.progress_container));
//getActivity().findViewById(android.R.id.empty).setVisibility(View.GONE);
setListAdapter(mAdapter);
registerForContextMenu(lv);
lv.setVerticalFadingEdgeEnabled(true);
}
if (dualPane) {
// In dual-pane mode, the list view highlights the selected item.
Log.d("lp", "dual pane mode");
lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
//lv.setVerticalScrollbarPosition(View.SCROLLBAR_POSITION_LEFT);
lv.setVerticalScrollBarEnabled(false);
lv.setFadingEdgeLength(50);
updateCheckedItem();
// Make sure our UI is in the correct state.
//showDetails(curCheckPosition, curCheckWizard);
}else {
//getListView().setVerticalScrollbarPosition(View.SCROLLBAR_POSITION_RIGHT);
lv.setVerticalScrollBarEnabled(true);
lv.setFadingEdgeLength(100);
}
}
@Override
public View onCreateView() {
LinearLayout ll_container = new LinearLayout(mContext);
ll_container.setOrientation(LinearLayout.VERTICAL);
ll_container.setBackgroundColor(Color.TRANSPARENT);
/** title */
mTvTitle = new TextView(mContext);
mTvTitle.setGravity(Gravity.CENTER);
mTvTitle.setPadding(dp2px(10), dp2px(5), dp2px(10), dp2px(5));
LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
params.topMargin = dp2px(20);
ll_container.addView(mTvTitle, params);
/** title underline */
mVLineTitle = new View(mContext);
ll_container.addView(mVLineTitle);
/** listview */
mLv = new ListView(mContext);
mLv.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 1));
mLv.setCacheColorHint(Color.TRANSPARENT);
mLv.setFadingEdgeLength(0);
mLv.setVerticalScrollBarEnabled(false);
mLv.setSelector(new ColorDrawable(Color.TRANSPARENT));
ll_container.addView(mLv);
TextView cancelDivider = new TextView(mContext);
cancelDivider.setGravity(Gravity.CENTER);
cancelDivider.setBackgroundColor(Color.parseColor("#ffefefef"));
LayoutParams clp = new LayoutParams(LayoutParams.MATCH_PARENT, 20);
cancelDivider.setLayoutParams(clp);
ll_container.addView(cancelDivider);
/** mCancel btn */
mTvCancel = new TextView(mContext);
mTvCancel.setGravity(Gravity.CENTER);
LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
lp.topMargin = dp2px(0);
lp.bottomMargin = dp2px(0);
mTvCancel.setLayoutParams(lp);
ll_container.addView(mTvCancel);
return ll_container;
}
@Override
public View onCreateView() {
LinearLayout ll_container = new LinearLayout(mContext);
ll_container.setOrientation(LinearLayout.VERTICAL);
ll_container.setBackgroundColor(Color.TRANSPARENT);
/** title */
mTvTitle = new TextView(mContext);
mTvTitle.setGravity(Gravity.CENTER);
mTvTitle.setPadding(dp2px(10), dp2px(5), dp2px(10), dp2px(5));
LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
params.topMargin = dp2px(20);
ll_container.addView(mTvTitle, params);
/** title underline */
mVLineTitle = new View(mContext);
ll_container.addView(mVLineTitle);
/** listview */
mLv = new ListView(mContext);
mLv.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 1));
mLv.setCacheColorHint(Color.TRANSPARENT);
mLv.setFadingEdgeLength(0);
mLv.setVerticalScrollBarEnabled(false);
mLv.setSelector(new ColorDrawable(Color.TRANSPARENT));
ll_container.addView(mLv);
/** mCancel btn */
mTvCancel = new TextView(mContext);
mTvCancel.setGravity(Gravity.CENTER);
LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
lp.topMargin = dp2px(7);
lp.bottomMargin = dp2px(7);
mTvCancel.setLayoutParams(lp);
ll_container.addView(mTvCancel);
return ll_container;
}
@Override
public View onCreateView() {
LinearLayout ll_container = new LinearLayout(mContext);
ll_container.setOrientation(LinearLayout.VERTICAL);
ll_container.setBackgroundColor(Color.TRANSPARENT);
/** title */
mTvTitle = new TextView(mContext);
mTvTitle.setGravity(Gravity.CENTER);
mTvTitle.setPadding(dp2px(10), dp2px(5), dp2px(10), dp2px(5));
LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
params.topMargin = dp2px(20);
ll_container.addView(mTvTitle, params);
/** title underline */
mVLineTitle = new View(mContext);
ll_container.addView(mVLineTitle);
/** listview */
mLv = new ListView(mContext);
mLv.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 1));
mLv.setCacheColorHint(Color.TRANSPARENT);
mLv.setFadingEdgeLength(0);
mLv.setVerticalScrollBarEnabled(false);
mLv.setSelector(new ColorDrawable(Color.TRANSPARENT));
ll_container.addView(mLv);
/** mCancel btn */
mTvCancel = new TextView(mContext);
mTvCancel.setGravity(Gravity.CENTER);
LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
lp.topMargin = dp2px(7);
lp.bottomMargin = dp2px(7);
mTvCancel.setLayoutParams(lp);
ll_container.addView(mTvCancel);
return ll_container;
}