Java Code Examples for android.widget.listview#setBackgroundColor()

The following examples show how to use android.widget.listview#setBackgroundColor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IconedListAdapter.java    From WhereYouGo with GNU General Public License v3.0 6 votes vote down vote up
public IconedListAdapter(Context context, ArrayList<DataInfo> data, View view) {
    this.mData = data;

    if (view instanceof ListView) {
        ListView listView = (ListView) view;
        listView.setBackgroundColor(Color.WHITE);
        this.type = TYPE_LIST_VIEW;
    } else if (view instanceof Spinner) {
        this.type = TYPE_SPINNER_VIEW;
    } else {
        setTextView02Visible(View.GONE, true);

        this.type = TYPE_OTHER;
    }

    this.context = context;
}
 
Example 2
Source File: PopupHomeActivity.java    From FlycoDialog_Master with MIT License 6 votes vote down vote up
@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);
}
 
Example 3
Source File: SimpleHomeActivity.java    From FlycoDialog_Master with MIT License 6 votes vote down vote up
@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);
}
 
Example 4
Source File: FireBaseActivity.java    From 30-android-libraries-in-30-days with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Random r = new Random();
    mUsername = "AhoyUser" + r.nextInt(1000);

    setContentView(R.layout.day30_activity_firebase);

    mButtonSend = (ImageButton) findViewById(R.id.button_send);
    mMessage = (EditText) findViewById(R.id.message);
    mListView = (ListView) findViewById(R.id.list_view);
    mListView.setBackgroundColor(Color.parseColor("#26B895"));

    mFirebase = new Firebase(AHOY_CHAT_URL).child("chat");

    queryData();

    mButtonSend.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            sendMessage();
        }
    });
}
 
Example 5
Source File: SignUpActivity.java    From Oy with Apache License 2.0 6 votes vote down vote up
/**
 * Makes a dialog to select the motherland
 */
public void makeMotherlandDialog() {
    final String[] options = getResources().getStringArray(R.array.motherlands);
    ListView listView = new ListView(this);
    listView.setAdapter(new MotherlandArrayAdapter(this, options));
    listView.setBackgroundColor(getResources().getColor(R.color.purple));
    final Dialog dialog = new AlertDialog.Builder(this).setView(listView).create();

    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int index, long id) {
            motherlandButton.setText(options[index]);
            dialog.dismiss();
        }
    });

    dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
    dialog.show();
}
 
Example 6
Source File: SettingsActivity.java    From buddycloud-android with Apache License 2.0 6 votes vote down vote up
@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();
	}
}
 
Example 7
Source File: AbsListContentWindow.java    From NetCloud_android with GNU General Public License v2.0 5 votes vote down vote up
private void initView(Context context){

        mContentView = new FrameLayout(context);

        mListView = new ListView(context);
        mListView.setDividerHeight(ScreenUtils.dp2px(1.5f));
        mListView.setDivider(new ColorDrawable(Color.TRANSPARENT));
        mListView.setSelector(R.drawable.list_item_bg);
        mListView.setBackgroundColor(Color.TRANSPARENT);
        mAdapter = new MyAdapter();

        mContentView.addView(mListView);

        mEmptyView = new TextView(context);
        mEmptyView.setTextSize(TypedValue.COMPLEX_UNIT_PX, ResTools.getDimen(R.dimen.textsize2));
        mEmptyView.setTextColor(ResTools.getColor(R.color.text));
        mEmptyView.setGravity(Gravity.CENTER);
        mEmptyView.setText("empty");
        FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        lp.gravity = Gravity.CENTER_HORIZONTAL;
        lp.topMargin = (int)(ScreenUtils.getScreenSize().y*0.38f);
        mContentView.addView(mEmptyView, lp);

        mLoading = new TextView(context);
        mLoading.setTextSize(TypedValue.COMPLEX_UNIT_PX, ResTools.getDimen(R.dimen.textsize2));
        mLoading.setTextColor(ResTools.getColor(R.color.text));
        mLoading.setText("loading...");
        lp = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        lp.gravity = Gravity.CENTER_HORIZONTAL;
        lp.topMargin = ScreenUtils.getScreenSize().y/3;
        mContentView.addView(mLoading, lp);
    }
 
Example 8
Source File: FrmPopMenu.java    From quickhybrid-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * 获取弹出视图
 *
 * @return
 */
public void setPopWindow() {
    ListView lv = new ListView(context);
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(DensityUtil.dip2px(context, 150), ViewGroup.LayoutParams.WRAP_CONTENT);
    lp.setMargins(15, 0, 15, 15);
    lv.setLayoutParams(lp);
    lv.setBackgroundColor(Color.WHITE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        lv.setElevation(15);
    }
    lv.setAdapter(new IconAdapter());
    lv.setOnItemClickListener(this);

    LinearLayout ll = new LinearLayout(context);
    ll.setLayoutParams(new ViewGroup.LayoutParams(DensityUtil.dip2px(context, 200), ViewGroup.LayoutParams.WRAP_CONTENT));
    ll.addView(lv);
    pop = new PopupWindow(ll, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
    pop.setTouchable(true);
    pop.setOutsideTouchable(true);
    //必须添加背景,否则点击空白无法自动隐藏
    pop.setBackgroundDrawable(new BitmapDrawable());
    pop.setOnDismissListener(new PopupWindow.OnDismissListener() {
        @Override
        public void onDismiss() {
            if (changedListener != null) {
                changedListener.onHide(FrmPopMenu.this);
            }
        }
    });
}
 
Example 9
Source File: DialogHelper.java    From ClassSchedule with Apache License 2.0 5 votes vote down vote up
/**
 * 底部列表弹窗
 */
public Dialog buildBottomListDialog(Activity activity, String[] items, final DialogListener listener) {
    ListView listView = new ListView(activity.getApplicationContext());
    listView.setDivider(new ColorDrawable(activity.getResources().getColor(R.color.color_divider)));
    listView.setDividerHeight(1);
    listView.setBackgroundColor(activity.getResources().getColor(R.color.white_f1));
    ArrayAdapter<String> adapter = new ArrayAdapter<>(activity, R.layout.adapter_bottom_dialog_sytle1, items);
    listView.setAdapter(adapter);


    final Dialog bottomDialog = new Dialog(activity, R.style.BottomDialog);

    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            listener.onItemClick(bottomDialog, position);
        }
    });

    bottomDialog.setContentView(listView);
    ViewGroup.LayoutParams layoutParams = listView.getLayoutParams();
    layoutParams.width = activity.getResources().getDisplayMetrics().widthPixels;
    listView.setLayoutParams(layoutParams);
    bottomDialog.getWindow().setGravity(Gravity.BOTTOM);
    bottomDialog.getWindow().setWindowAnimations(R.style.BottomDialog_Animation);

    return bottomDialog;
}
 
Example 10
Source File: GeocodingBaseActivity.java    From mobile-android-samples with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    inputField = new EditText(this);
    inputField.setTextColor(Color.WHITE);
    inputField.setBackgroundColor(Colors.DARK_TRANSPARENT_GRAY);
    inputField.setHint("Type address...");
    inputField.setHintTextColor(Color.LTGRAY);
    inputField.setSingleLine();
    inputField.setImeOptions(EditorInfo.IME_ACTION_DONE);

    int totalWidth = getResources().getDisplayMetrics().widthPixels;
    int padding = (int)(5 * getResources().getDisplayMetrics().density);

    int width = totalWidth - 2 * padding;
    int height = (int)(45 * getResources().getDisplayMetrics().density);

    RelativeLayout.LayoutParams parameters = new RelativeLayout.LayoutParams(width, height);
    parameters.setMargins(padding, padding, 0, 0);
    addContentView(inputField, parameters);

    resultTable = new ListView(this);
    resultTable.setBackgroundColor(Colors.LIGHT_TRANSPARENT_GRAY);

    height = (int)(200 * getResources().getDisplayMetrics().density);

    parameters = new RelativeLayout.LayoutParams(width, height);
    parameters.setMargins(padding, 2 * padding + inputField.getLayoutParams().height, 0, 0);

    addContentView(resultTable, parameters);

    adapter = new GeocodingResultAdapter(this);
    adapter.width = width;
    resultTable.setAdapter(adapter);

    hideTable();
}
 
Example 11
Source File: FilePicker.java    From AndroidPicker with MIT License 5 votes vote down vote up
@Override
@NonNull
protected LinearLayout makeCenterView() {
    LinearLayout rootLayout = new LinearLayout(activity);
    rootLayout.setLayoutParams(new LinearLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT));
    rootLayout.setOrientation(LinearLayout.VERTICAL);
    rootLayout.setBackgroundColor(Color.WHITE);

    ListView listView = new ListView(activity);
    listView.setBackgroundColor(Color.WHITE);
    listView.setDivider(new ColorDrawable(0xFFDDDDDD));
    listView.setDividerHeight(1);
    listView.setCacheColorHint(Color.TRANSPARENT);
    listView.setLayoutParams(new LinearLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT));
    listView.setAdapter(adapter);
    listView.setOnItemClickListener(this);
    rootLayout.addView(listView);

    emptyView = new TextView(activity);
    LinearLayout.LayoutParams txtParams = new LinearLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT);
    txtParams.gravity = Gravity.CENTER;
    emptyView.setLayoutParams(txtParams);
    emptyView.setGravity(Gravity.CENTER);
    emptyView.setVisibility(View.GONE);
    emptyView.setTextColor(Color.BLACK);
    rootLayout.addView(emptyView);

    return rootLayout;
}
 
Example 12
Source File: SettingActivity.java    From qingyang with Apache License 2.0 5 votes vote down vote 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();

}
 
Example 13
Source File: UIHelper.java    From iSCAU-Android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 14
Source File: PopupWindowList.java    From WechatPopupWindow with Apache License 2.0 4 votes vote down vote up
public void show() {
    if (mAnchorView == null) {
        throw new IllegalArgumentException("PopupWindow show location view can  not be null");
    }
    if (mItemData == null) {
        throw new IllegalArgumentException("please fill ListView Data");
    }
    mPopView = new ListView(mContext);
    mPopView.setBackgroundColor(ContextCompat.getColor(mContext, android.R.color.white));
    mPopView.setVerticalScrollBarEnabled(false);
    mPopView.setDivider(null);
    mPopView.setAdapter(new ArrayAdapter<>(mContext,
            android.R.layout.simple_list_item_1, mItemData));
    if (mItemClickListener != null) {
        mPopView.setOnItemClickListener(mItemClickListener);
    }
    mPopView.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
            View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
    if (mPopupWindowWidth == 0) {
        mPopupWindowWidth = mDeviceWidth / 3;
    }
    if (mPopupWindowHeight == 0) {
        mPopupWindowHeight = mItemData.size() * mPopView.getMeasuredHeight();
        if (mPopupWindowHeight > mDeviceHeight / 2) {
            mPopupWindowHeight = mDeviceHeight / 2;
        }
    }
    mPopupWindow = new PopupWindow(mPopView, mPopupWindowWidth, mPopupWindowHeight);
    if (mPopAnimStyle != 0) {
        mPopupWindow.setAnimationStyle(mPopAnimStyle);
    }
    mPopupWindow.setOutsideTouchable(true);
    mPopupWindow.setFocusable(mModal);
    mPopupWindow.setBackgroundDrawable(new BitmapDrawable(mContext.getResources(), (Bitmap) null));


    Rect location = locateView(mAnchorView);
    if (location != null) {
        int x;
        //view中心点X坐标
        int xMiddle = location.left + mAnchorView.getWidth() / 2;
        if (xMiddle > mDeviceWidth / 2) {
            //在右边
            x = xMiddle - mPopupWindowWidth;
        } else {
            x = xMiddle;
        }
        int y;
        //view中心点Y坐标
        int yMiddle = location.top + mAnchorView.getHeight() / 2;
        if (yMiddle > mDeviceHeight / 2) {
            //在下方
            y = yMiddle - mPopupWindowHeight;
        } else {
            //在上方
            y = yMiddle;
        }
        mPopupWindow.showAtLocation(mAnchorView, Gravity.NO_GRAVITY, x, y);
    }
}
 
Example 15
Source File: DebugOverlayView.java    From debugoverlay with Apache License 2.0 4 votes vote down vote up
public DebugOverlayView(Context context) {
  super(context);

  windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
  Point windowDimen = new Point();
  windowManager.getDefaultDisplay().getSize(windowDimen);

  int desiredLayoutHeight = dpToPx(context, 100);
  int layoutHeight = desiredLayoutHeight < windowDimen.y ? desiredLayoutHeight : windowDimen.y;

  // Setup the GUI

  // Close Button
  int buttonHeight = dpToPx(context, 40);
  closeButton = new ImageView(context);
  closeButton.setImageResource(R.drawable.ic_close_circle);
  closeButton.setLayoutParams(new FrameLayout.LayoutParams(buttonHeight, buttonHeight, Gravity.TOP | Gravity.END));

  // Logging Console
  adapter = new LoggingAdapter(context);
  listView = new ListView(context);
  listView.setBackgroundColor(Color.parseColor("#64000000"));
  listView.setTranscriptMode(AbsListView.TRANSCRIPT_MODE_ALWAYS_SCROLL);
  listView.setStackFromBottom(true);
  listView.setAdapter(adapter);
  FrameLayout.LayoutParams listViewLayoutParams =
      new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
  listViewLayoutParams.topMargin = buttonHeight / 2;
  listView.setLayoutParams(listViewLayoutParams);

  // Add views
  addView(listView);
  addView(closeButton);

  // Set View parameters
  WindowManager.LayoutParams windowParams;
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    windowParams = new WindowManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, layoutHeight,
        WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.TRANSLUCENT);
  } else {
    windowParams =
        new WindowManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, layoutHeight, WindowManager.LayoutParams.TYPE_PHONE,
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.TRANSLUCENT);
  }

  windowParams.gravity = Gravity.TOP | Gravity.START;
  windowParams.x = 0;
  windowParams.y = windowDimen.y - layoutHeight;

  // Attach and display View
  windowManager.addView(this, windowParams);
}
 
Example 16
Source File: SocialAuthAdapter.java    From socialauth-android with MIT License 4 votes vote down vote up
/**
 * Enables a button with the SocialAuth menu
 * 
 * @param actionView
 *            The button on providersthat will be clicked by user to show
 *            list of providers
 */
public void enable(final View actionView) {

	// Creating List to show providers
	final Context ctx = actionView.getContext();
	final ListView pList = new ListView(ctx);
	pList.setLayoutParams(new LinearLayout.LayoutParams(500, 500));
	pList.setBackgroundColor(Color.WHITE);

	// Getting provider names and logos to display
	final String[] providerNames = new String[providerCount];
	final int[] providerLogos = new int[providerCount];

	for (int i = 0; i < providerCount; i++) {
		providerNames[i] = authProviders[i].toString();
		providerLogos[i] = authProviderLogos[i];
	}

	// Query native apps
	final ArrayList<AppList> appList = Util.queryIntentActivities(ctx, providerNames, providerLogos);

	// Handle Click Events on Action Provider button
	actionView.setOnClickListener(new OnClickListener() {

		@Override
		public void onClick(View v) {

			// Populating List
			pList.setAdapter(new PopUpListAdapter(ctx, appList));
			pList.setDivider(new ColorDrawable(0x99474747));

			// Creating Popup Window to show List
			final PopupWindow popupWindow = new PopupWindow(ctx);
			popupWindow.setFocusable(true);
			WindowManager wm = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
			float width = (wm.getDefaultDisplay().getWidth() * 2) / 3;
			popupWindow.setWidth((int) width);
			popupWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);

			// set the list view as pop up window content
			popupWindow.setContentView(pList);
			popupWindow.showAsDropDown(actionView, 10, 10);

			// Handle Click events on list item
			pList.setOnItemClickListener(new OnItemClickListener() {
				@Override
				public void onItemClick(AdapterView<?> adapter, View view, int position, long arg) {

					// Dismiss popup window
					popupWindow.dismiss();

					// Start provider
					if (position > providerNames.length) {
						ctx.startActivity(appList.get(position).intent);

					} else {
						authorize(ctx, authProviders[position]);
					}
				}
			});
		}
	});

	// If network not available show message
	if (!Util.isNetworkAvailable(ctx)) {
		dialogListener.onError(new SocialAuthError("Please check your Internet connection", new Exception("")));
		return;
	}
}