Java Code Examples for android.widget.TextView.setBackgroundResource()

The following are Jave code examples for showing how to use setBackgroundResource() of the android.widget.TextView class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Quran   File: SlidingTabLayout.java   View Source Code Vote up 6 votes
/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}.
 */
protected TextView createDefaultTabView(Context context) {
  TextView textView = new TextView(context);
  textView.setGravity(Gravity.CENTER);
  textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
  textView.setTypeface(Typeface.DEFAULT_BOLD);
  textView.setSingleLine();
  textView.setTextColor(mUnselectedTabColor);

  // If we're running on Honeycomb or newer, then we can use the Theme's
  // selectableItemBackground to ensure that the View has a pressed state
  TypedValue outValue = new TypedValue();
  getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground,
      outValue, true);
  textView.setBackgroundResource(outValue.resourceId);
  textView.setAllCaps(true);

  int padding = mTabPadding;
  textView.setPadding(padding, padding, padding, padding);

  return textView;
}
 
Example 2
Project: CSipSimple   File: IcsToast.java   View Source Code Vote up 6 votes
public static Toast makeText(Context context, CharSequence s, int duration) {
    if (VERSION.SDK_INT >= VERSION_CODES.ICE_CREAM_SANDWICH) {
        return Toast.makeText(context, s, duration);
    }
    IcsToast toast = new IcsToast(context);
    toast.setDuration(duration);
    TextView view = new TextView(context);
    view.setText(s);
    // Original AOSP using reference on @android:color/bright_foreground_dark
    // bright_foreground_dark - reference on @android:color/background_light
    // background_light - 0xffffffff
    view.setTextColor(0xffffffff);
    view.setGravity(Gravity.CENTER);
    view.setBackgroundResource(R.drawable.abs__toast_frame);
    toast.setView(view);
    return toast;
}
 
Example 3
Project: GitHub   File: SuperAwesomeCardFragment.java   View Source Code Vote up 6 votes
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

	LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);

	FrameLayout fl = new FrameLayout(getActivity());
	fl.setLayoutParams(params);

	final int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getResources()
			.getDisplayMetrics());

	TextView v = new TextView(getActivity());
	params.setMargins(margin, margin, margin, margin);
	v.setLayoutParams(params);
	v.setLayoutParams(params);
	v.setGravity(Gravity.CENTER);
	v.setBackgroundResource(R.drawable.background_card);
	v.setText("CARD " + (position + 1));

	fl.addView(v);
	return fl;
}
 
Example 4
Project: RLibrary   File: UIBottomItemDialog.java   View Source Code Vote up 6 votes
@Override
protected void inflateItem() {
    int size = mItemInfos.size();
    for (int i = 0; i < size; i++) {
        ItemInfo info = mItemInfos.get(i);
        TextView textView = createItem(info);
        if (useWxStyle) {
            textView.setTextColor(getWxStyleTextColor());
        } else {
            textView.setTextColor(getColor(R.color.base_text_color));
        }
        textView.setBackgroundResource(R.drawable.base_bg_selector);
        mItemContentLayout.addView(textView,
                new ViewGroup.LayoutParams(-1,
                        mActivity.getResources().getDimensionPixelSize(R.dimen.base_item_size)));
    }
}
 
Example 5
Project: YCDialog   File: DialogAdapter.java   View Source Code Vote up 6 votes
TopHolder(View view) {
    super(view);

    ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    params.width = getScreenWidth(context) / 5;

    item = new TextView(view.getContext());
    item.setLayoutParams(params);
    item.setMaxLines(1);
    item.setEllipsize(TextUtils.TruncateAt.END);
    item.setGravity(Gravity.CENTER);
    item.setTextColor(ContextCompat.getColor(view.getContext(), R.color.gray_dark));
    item.setTextSize(TypedValue.COMPLEX_UNIT_PX, context.getResources().getDimension(R.dimen.app_normal_margin));
    item.setCompoundDrawablePadding(topPadding);
    item.setPadding(0, padding, 0, padding);

    TypedValue typedValue = new TypedValue();
    view.getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, typedValue, true);
    item.setBackgroundResource(typedValue.resourceId);

    ((LinearLayout) view).addView(item);
}
 
Example 6
Project: foodie   File: Chats.java   View Source Code Vote up 6 votes
public void addMessageBox(String message, int type){
    TextView textView = new TextView(getActivity()); //dunno what to do here
    textView.setText(message);
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    lp.setMargins(0, 0, 0, 10);
    textView.setLayoutParams(lp);

    if(type == 1) {
        textView.setBackgroundResource(R.drawable.bubble_in);
    }
    else{
        textView.setBackgroundResource(R.drawable.bubble_out);
    }

    layout.addView(textView);
    scrollView.fullScroll(View.FOCUS_DOWN);
}
 
Example 7
Project: TaipeiTechRefined   File: CreditGeneralView.java   View Source Code Vote up 6 votes
private void init() {
    container = new LinearLayout(getContext());
    container.setOrientation(LinearLayout.VERTICAL);
    container.setBackgroundResource(R.color.silver);
    for (GeneralCredit general : studentCredit.getGeneralCredits()) {
        LayoutInflater inflater = LayoutInflater.from(getContext());
        TextView title_text = (TextView) inflater.inflate(
                R.layout.credit_textview, this, false);
        title_text.setBackgroundResource(R.color.cloud);
        title_text.setTypeface(title_text.getTypeface(), Typeface.BOLD);
        title_text.setText(general.getTypeName());
        container.addView(title_text);
        TextView text = (TextView) inflater.inflate(
                R.layout.credit_textview, this, false);
        text.setBackgroundResource(R.color.white);
        String credit_text = getContext().getString(R.string.credit_essential_core) + general.getMustCoreCredit()
                + "  "+getContext().getString(R.string.credit_general_core) + general.getHadCoreCredit() + "  " + getContext().getString(R.string.credit_general_elective)
                + general.getHadCommonCredit();
        text.setText(credit_text);
        container.addView(text);
        addData(general);
    }
    addView(container);
}
 
Example 8
Project: GitHub   File: GridPickerView.java   View Source Code Vote up 5 votes
/**添加tab
 * @param tabPosition
 * @param tabWidth
 * @param name
 */
@SuppressLint("NewApi")
private void addTab(final int tabPosition, int tabWidth, String name) {
	if (StringUtil.isNotEmpty(name, true) == false) {
		return;
	}
	name = StringUtil.getTrimedString(name);

	final TextView tvTab = new TextView(context);
	tvTab.setLayoutParams(new LayoutParams(tabWidth, LayoutParams.MATCH_PARENT));
	tvTab.setGravity(Gravity.CENTER);
	//		tvTab.setPaddingRelative(4, 12, 4, 12);
	tvTab.setTextColor(context.getResources().getColor(R.color.black));
	tvTab.setBackgroundResource(R.drawable.to_alpha);
	tvTab.setTextSize(18);
	tvTab.setSingleLine(true);
	tvTab.setText(name);
	tvTab.setOnClickListener(new OnClickListener() {
		@Override
		public void onClick(View v) {
			if (tabPosition == getCurrentTabPosition()) {
				return;
			}

			if (onTabClickListener != null) {
				onTabClickListener.onTabClick(tabPosition, tvTab);
				return;
			}
			//点击就是要切换list,这些配置都要改bindView(tabSuffix, tabPosition, tabName, list, numColumns, maxShowRows, itemPosition)
		}
	});
	llGridPickerViewTabContainer.addView(tvTab);
}
 
Example 9
Project: decoy   File: LoginActivity.java   View Source Code Vote up 5 votes
public TextView addRegisterRightTopBtn(UI activity, int strResId) {
    String text = activity.getResources().getString(strResId);
    TextView textView = findView(R.id.action_bar_right_clickable_textview);
    textView.setText(text);
    if (textView != null) {
        textView.setBackgroundResource(R.drawable.register_right_top_btn_selector);
        textView.setPadding(ScreenUtil.dip2px(10), 0, ScreenUtil.dip2px(10), 0);
    }
    return textView;
}
 
Example 10
Project: letv   File: AlbumVideoController.java   View Source Code Vote up 5 votes
private void setButtonSelect(TextView textView, boolean select) {
    if (!this.mActivity.mIsPlayingNonCopyright) {
        if (select) {
            textView.setBackgroundResource(R.drawable.bg_btn_play_full_selected);
            return;
        }
        textView.setTextAppearance(this.mActivity, R.style.play_controller_btn_text);
        textView.setBackgroundResource(R.drawable.btn_play_live_full_func_bg_selector);
    }
}
 
Example 11
Project: KUtils   File: SmartTabLayout.java   View Source Code Vote up 5 votes
/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}.
 */
protected TextView createDefaultTabView(CharSequence title) {
  TextView textView = new TextView(getContext());
  textView.setGravity(Gravity.CENTER);
  textView.setText(title);
  textView.setTextColor(tabViewTextColors);
  textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabViewTextSize);
  textView.setTypeface(Typeface.DEFAULT_BOLD);
  textView.setLayoutParams(new LinearLayout.LayoutParams(
      LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT));

  if (tabViewBackgroundResId != NO_ID) {
    textView.setBackgroundResource(tabViewBackgroundResId);
  } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
    // If we're running on Honeycomb or newer, then we can use the Theme's
    // selectableItemBackground to ensure that the View has a pressed state
    TypedValue outValue = new TypedValue();
    getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground,
        outValue, true);
    textView.setBackgroundResource(outValue.resourceId);
  }

  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
    // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style
    textView.setAllCaps(tabViewTextAllCaps);
  }

  textView.setPadding(
      tabViewTextHorizontalPadding, 0,
      tabViewTextHorizontalPadding, 0);

  if (tabViewTextMinWidth > 0) {
    textView.setMinWidth(tabViewTextMinWidth);
  }

  return textView;
}
 
Example 12
Project: Android-SteamVR-controller   File: ControllerFragment.java   View Source Code Vote up 5 votes
private void OnButtonTouchEvent(TextView button, boolean touchDown) {
    if (touchDown) {
        button.setBackgroundResource(R.drawable.circle_highlighted);
    }
    else {
        button.setBackgroundResource(R.drawable.circle);
    }
}
 
Example 13
Project: Raffler-Android   File: AlertView.java   View Source Code Vote up 5 votes
protected void initListView(){
    Context context = contextWeak.get();
    if(context == null) return;

    ListView alertButtonListView = (ListView) contentContainer.findViewById(R.id.alertButtonListView);

    if(cancel != null && style == Style.Alert){
        View itemView = LayoutInflater.from(context).inflate(R.layout.item_actionsheetbutton, null);
        TextView tvAlert = (TextView) itemView.findViewById(R.id.tvAlert);
        tvAlert.setText(cancel);
        tvAlert.setClickable(true);
        tvAlert.setTypeface(Typeface.DEFAULT_BOLD);
        tvAlert.setTextColor(context.getResources().getColor(R.color.textColor_alert_button_cancel));
        tvAlert.setBackgroundResource(R.drawable.bg_alertbutton_bottom);
        tvAlert.setOnClickListener(new OnTextClickListener(CANCELPOSITION));
        alertButtonListView.addFooterView(itemView);
    }
    AlertViewAdapter adapter = new AlertViewAdapter(mDatas,mDestructive);
    alertButtonListView.setAdapter(adapter);
    alertButtonListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
            if(onItemClickListener != null)onItemClickListener.onItemClick(AlertView.this,position);
            dismiss();
        }
    });
}
 
Example 14
Project: BBSSDK-for-Android   File: DefaultChooserDialog.java   View Source Code Vote up 4 votes
private void init(Context context) {
	setCanceledOnTouchOutside(true);//触摸屏幕取消窗体
	setCancelable(true);//按返回键取消窗体
	Window window = getWindow();
	window.setWindowAnimations(ResHelper.getStyleRes(context, "BBS_AnimUpDown"));

	//setup view
	LinearLayout containLayout = new LinearLayout(context);
	containLayout.setOrientation(LinearLayout.VERTICAL);
	int leftPadding = ResHelper.dipToPx(context, 16);
	containLayout.setPadding(leftPadding, 0, leftPadding, leftPadding / 2);
	window.setContentView(containLayout, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));

	if (listItems.size() > 0) {
		LinearLayout itemContainer = new LinearLayout(context);
		itemContainer.setOrientation(LinearLayout.VERTICAL);
		itemContainer.setBackgroundResource(ResHelper.getBitmapRes(context, "bbs_chooser_dialog_item_bg"));
		LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
		containLayout.addView(itemContainer, llp);

		//添加item
		int dividerHeight = context.getResources()
				.getDimensionPixelSize(ResHelper.getResId(context, "dimen", "bbs_chooser_dialog_divider_height"));
		int itemHeight = context.getResources().getDimensionPixelSize(ResHelper.getResId(context, "dimen", "bbs_chooser_dialog_item_height"));
		int txtSize = context.getResources().getDimensionPixelSize(ResHelper.getResId(context, "dimen", "bbs_chooser_dialog_txt_size"));
		int txtColor = context.getResources().getColor(ResHelper.getColorRes(context, "bbs_chooser_dialog_txt_color"));
		int length = listItems.size();
		tvItems = new SparseArray<TextView>(length);
		int topBgRes = ResHelper.getBitmapRes(context, "bbs_chooser_dialog_item_bg_top");
		int middleBgRes = ResHelper.getBitmapRes(context, "bbs_chooser_dialog_item_bg_middle");
		int bottomBgRes = ResHelper.getBitmapRes(context, "bbs_chooser_dialog_item_bg_bottom");
		for (int i = 0; i < length; i++) {
			int tag = i + 1;
			TextView tvItem = new TextView(context);
			tvItem.setTag(tag);
			tvItem.setGravity(Gravity.CENTER);
			tvItem.setTextColor(txtColor);
			tvItem.setTextSize(TypedValue.COMPLEX_UNIT_PX, txtSize);
			tvItem.setText(listItems.get(i));
			if (i == 0 && length > 1) {
				tvItem.setBackgroundResource(topBgRes);
			} else if (i == length - 1 && length > 1) {
				tvItem.setBackgroundResource(bottomBgRes);
			} else {
				tvItem.setBackgroundResource(middleBgRes);
			}
			llp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, itemHeight);
			itemContainer.addView(tvItem, llp);

			if (i < length - 1) {
				View vLine1 = new View(context);
				vLine1.setBackgroundColor(0xFFB7B7B7);
				llp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, dividerHeight);
				itemContainer.addView(vLine1, llp);
			}
			tvItems.put(tag, tvItem);
		}

		TextView tvCancel = new TextView(context);
		tvCancel.setTag(0);
		tvCancel.setGravity(Gravity.CENTER);
		tvCancel.setTextColor(context.getResources().getColor(ResHelper.getColorRes(context, "bbs_chooser_dialog_cancel_txt_color")));
		tvCancel.setTextSize(TypedValue.COMPLEX_UNIT_PX, txtSize);
		tvCancel.setText(ResHelper.getStringRes(context, "bbs_cancel"));
		tvCancel.setBackgroundResource(ResHelper.getBitmapRes(context, "bbs_chooser_dialog_item_bg"));
		llp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, itemHeight);
		llp.topMargin = ResHelper.dipToPx(context, 10);
		containLayout.addView(tvCancel, llp);

		tvItems.put(0, tvCancel);
	}
}
 
Example 15
Project: android-RibbonViews   File: RibbonLayout.java   View Source Code Vote up 4 votes
private void onCreate() {
    ribbon_header = new TextView(getContext());
    ribbon_header.setBackgroundResource(R.drawable.rectangle_layout);
    ribbon_bottom = new TextView(getContext());
}
 
Example 16
Project: cafebar   File: CafeBarUtil.java   View Source Code Vote up 4 votes
@NonNull
static TextView getActionView(@NonNull CafeBar.Builder builder, @NonNull String action, int color) {
    boolean longAction = isLongAction(action);
    int res = R.layout.cafebar_action_button_dark;

    CafeBarTheme.Custom customTheme = builder.mTheme;
    int titleColor = customTheme.getTitleColor();
    boolean dark = titleColor != Color.WHITE;
    if (dark) {
        res = R.layout.cafebar_action_button;
    }

    int padding = builder.mContext.getResources().getDimensionPixelSize(
            R.dimen.cafebar_button_padding);

    TextView button = (TextView) View.inflate(builder.mContext, res, null);
    button.setText(action.toUpperCase(Locale.getDefault()));
    button.setMaxLines(1);
    button.setEllipsize(TextUtils.TruncateAt.END);
    button.setTextColor(color);
    button.setPadding(padding, padding, padding, padding);

    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);

    int side = builder.mContext.getResources().getDimensionPixelSize(
            R.dimen.cafebar_content_padding_side);
    int margin = builder.mContext.getResources().getDimensionPixelSize(
            R.dimen.cafebar_button_margin_start);
    params.setMargins(margin, 0, 0, 0);

    if (longAction) {
        params.setMargins(0, (side - padding), 0, 0);
    }

    if (builder.mPositiveText != null || builder.mNegativeText != null) {
        longAction = true;
        params.setMargins(0, (side - padding), 0, 0);
    } else {
        params.gravity = Gravity.CENTER_VERTICAL | Gravity.END;
    }

    button.setLayoutParams(params);

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        button.setBackgroundResource(dark ? R.drawable.cafebar_action_button_selector_dark :
                R.drawable.cafebar_action_button_selector);
        return button;
    }

    TypedValue outValue = new TypedValue();
    builder.mContext.getTheme().resolveAttribute(longAction ?
                    R.attr.selectableItemBackground : R.attr.selectableItemBackgroundBorderless,
            outValue, true);
    button.setBackgroundResource(outValue.resourceId);
    return button;
}
 
Example 17
Project: wulkanowy   File: GradesDialogFragment.java   View Source Code Vote up 4 votes
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.grades_dialog, container, false);

    TextView gradeText = view.findViewById(R.id.dialog_grade_text);
    TextView subjectText = view.findViewById(R.id.subject_dialog_text_value);
    TextView descriptionText = view.findViewById(R.id.description_dialog_text_value);
    TextView weightText = view.findViewById(R.id.weight_dialog_text_value);
    TextView teacherText = view.findViewById(R.id.teacher_dialog_text_value);
    TextView dateText = view.findViewById(R.id.date_dialog_text_value);
    TextView colorText = view.findViewById(R.id.color_dialog_text_value);
    Button closeDialog = view.findViewById(R.id.close_dialog);

    subjectText.setText(grade.getSubject());
    gradeText.setText(grade.getValue());
    gradeText.setBackgroundResource(grade.getValueColor());
    weightText.setText(grade.getWeight());
    dateText.setText(grade.getDate());
    colorText.setText(colorHexToColorName(grade.getColor()));

    if ("".equals(grade.getDescription())) {
        if (!"".equals(grade.getSymbol())) {
            descriptionText.setText(grade.getSymbol());
        }
    } else if (!"".equals(grade.getSymbol())) {
        descriptionText.setText(String.format("%1$s - %2$s", grade.getSymbol(), grade.getDescription()));
    } else {
        descriptionText.setText(grade.getDescription());
    }

    if (!"".equals(grade.getTeacher())) {
        teacherText.setText(grade.getTeacher());
    }

    closeDialog.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dismiss();
        }
    });

    return view;
}
 
Example 18
Project: boohee_v5.6   File: EditPage.java   View Source Code Vote up 4 votes
private LinearLayout getAtLine(String platform) {
    if (!isShowAtUserLayout(platform)) {
        return null;
    }
    LinearLayout llAt = new LinearLayout(getContext());
    LinearLayout.LayoutParams lpAt = new LinearLayout.LayoutParams(-2, -2);
    lpAt.rightMargin = R.dipToPx(getContext(), 4);
    lpAt.gravity = 83;
    lpAt.weight = 1.0f;
    llAt.setLayoutParams(lpAt);
    llAt.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            FollowListPage subPage = new FollowListPage();
            subPage.setPlatform((Platform) EditPage.this.platforms.get(0));
            subPage.showForResult(EditPage.this.activity, null, EditPage.this);
        }
    });
    TextView tvAt = new TextView(getContext());
    int resId = R.getBitmapRes(this.activity, "btn_back_nor");
    if (resId > 0) {
        tvAt.setBackgroundResource(resId);
    }
    int dp_32 = R.dipToPx(getContext(), 32);
    tvAt.setLayoutParams(new LinearLayout.LayoutParams(dp_32, dp_32));
    tvAt.setTextSize(1, 18.0f);
    tvAt.setText(getAtUserButtonText(platform));
    tvAt.setPadding(0, 0, 0, R.dipToPx(getContext(), 2));
    tvAt.setTypeface(Typeface.DEFAULT_BOLD);
    tvAt.setTextColor(-16777216);
    tvAt.setGravity(17);
    llAt.addView(tvAt);
    TextView tvName = new TextView(getContext());
    tvName.setTextSize(1, 18.0f);
    tvName.setTextColor(-16777216);
    resId = R.getStringRes(this.activity, "list_friends");
    tvName.setText(getContext().getString(resId, new Object[]{getName(platform)}));
    LinearLayout.LayoutParams lpName = new LinearLayout.LayoutParams(-2, -2);
    lpName.gravity = 16;
    tvName.setLayoutParams(lpName);
    llAt.addView(tvName);
    return llAt;
}
 
Example 19
Project: AOSP-Kayboard-7.1.2   File: EmojiPalettesView.java   View Source Code Vote up 4 votes
@Override
protected void onFinishInflate() {
    mTabHost = (TabHost)findViewById(R.id.emoji_category_tabhost);
    mTabHost.setup();
    for (final EmojiCategory.CategoryProperties properties
            : mEmojiCategory.getShownCategories()) {
        addTab(mTabHost, properties.mCategoryId);
    }
    mTabHost.setOnTabChangedListener(this);
    final TabWidget tabWidget = mTabHost.getTabWidget();
    tabWidget.setStripEnabled(mCategoryIndicatorEnabled);
    if (mCategoryIndicatorEnabled) {
        // On TabWidget's strip, what looks like an indicator is actually a background.
        // And what looks like a background are actually left and right drawables.
        tabWidget.setBackgroundResource(mCategoryIndicatorDrawableResId);
        tabWidget.setLeftStripDrawable(mCategoryIndicatorBackgroundResId);
        tabWidget.setRightStripDrawable(mCategoryIndicatorBackgroundResId);
    }

    mEmojiPalettesAdapter = new EmojiPalettesAdapter(mEmojiCategory, this);

    mEmojiPager = (ViewPager)findViewById(R.id.emoji_keyboard_pager);
    mEmojiPager.setAdapter(mEmojiPalettesAdapter);
    mEmojiPager.setOnPageChangeListener(this);
    mEmojiPager.setOffscreenPageLimit(0);
    mEmojiPager.setPersistentDrawingCache(PERSISTENT_NO_CACHE);
    mEmojiLayoutParams.setPagerProperties(mEmojiPager);

    mEmojiCategoryPageIndicatorView =
            (EmojiCategoryPageIndicatorView)findViewById(R.id.emoji_category_page_id_view);
    mEmojiCategoryPageIndicatorView.setColors(
            mCategoryPageIndicatorColor, mCategoryPageIndicatorBackground);
    mEmojiLayoutParams.setCategoryPageIdViewProperties(mEmojiCategoryPageIndicatorView);

    setCurrentCategoryId(mEmojiCategory.getCurrentCategoryId(), true /* force */);

    final LinearLayout actionBar = (LinearLayout)findViewById(R.id.emoji_action_bar);
    mEmojiLayoutParams.setActionBarProperties(actionBar);

    // deleteKey depends only on OnTouchListener.
    mDeleteKey = (ImageButton)findViewById(R.id.emoji_keyboard_delete);
    mDeleteKey.setBackgroundResource(mFunctionalKeyBackgroundId);
    mDeleteKey.setTag(Constants.CODE_DELETE);
    mDeleteKey.setOnTouchListener(mDeleteKeyOnTouchListener);

    // {@link #mAlphabetKeyLeft}, {@link #mAlphabetKeyRight, and spaceKey depend on
    // {@link View.OnClickListener} as well as {@link View.OnTouchListener}.
    // {@link View.OnTouchListener} is used as the trigger of key-press, while
    // {@link View.OnClickListener} is used as the trigger of key-release which does not occur
    // if the event is canceled by moving off the finger from the view.
    // The text on alphabet keys are set at
    // {@link #startEmojiPalettes(String,int,float,Typeface)}.
    mAlphabetKeyLeft = (TextView)findViewById(R.id.emoji_keyboard_alphabet_left);
    mAlphabetKeyLeft.setBackgroundResource(mFunctionalKeyBackgroundId);
    mAlphabetKeyLeft.setTag(Constants.CODE_ALPHA_FROM_EMOJI);
    mAlphabetKeyLeft.setOnTouchListener(this);
    mAlphabetKeyLeft.setOnClickListener(this);
    mAlphabetKeyRight = (TextView)findViewById(R.id.emoji_keyboard_alphabet_right);
    mAlphabetKeyRight.setBackgroundResource(mFunctionalKeyBackgroundId);
    mAlphabetKeyRight.setTag(Constants.CODE_ALPHA_FROM_EMOJI);
    mAlphabetKeyRight.setOnTouchListener(this);
    mAlphabetKeyRight.setOnClickListener(this);
    mSpacebar = findViewById(R.id.emoji_keyboard_space);
    mSpacebar.setBackgroundResource(mSpacebarBackgroundId);
    mSpacebar.setTag(Constants.CODE_SPACE);
    mSpacebar.setOnTouchListener(this);
    mSpacebar.setOnClickListener(this);
    mEmojiLayoutParams.setKeyProperties(mSpacebar);
    mSpacebarIcon = findViewById(R.id.emoji_keyboard_space_icon);
}
 
Example 20
Project: UIWidget   File: UIActionSheetView.java   View Source Code Vote up 4 votes
/**
 * 生成条目
 */
private void setSheetItems() {
    if (listSheetItem == null || listSheetItem.size() <= 0) {
        return;
    }
    lLayoutItem.setGravity(STYLE == STYLE_WEI_XIN ? Gravity.LEFT | Gravity.CENTER_VERTICAL : Gravity.CENTER);
    lLayoutItem.removeAllViews();
    // 循环添加条目
    for (int i = 0; i <= listSheetItem.size() - 1; i++) {
        final int item = i;
        SheetItem sheetItem = listSheetItem.get(i);
        final OnSheetItemListener listener = sheetItem.itemClickListener;
        View view = new View(context);

        TextView textView = new TextView(context);
        textView.setText(sheetItem.name);
        textView.setTextSize(unitItems, textSizeItems);
        textView.setGravity(STYLE == STYLE_WEI_XIN ? Gravity.LEFT | Gravity.CENTER_VERTICAL : Gravity.CENTER);
        textView.setPadding(dip2px(mPaddingLeft), dip2px(mPaddingTop), dip2px(mPaddingLeft), dip2px(mPaddingTop));
        vLineTitle.setVisibility(showTitle && STYLE == STYLE_NORMAL ? View.VISIBLE : View.GONE);
        // 背景图片
        if (STYLE == STYLE_IOS) {
            if (listSheetItem.size() == 1) {
                if (showTitle) {
                    textView.setBackgroundResource(R.drawable.action_sheet_bottom);
                } else {
                    textView.setBackgroundResource(R.drawable.action_sheet_single);
                }
            } else {
                if (showTitle) {
                    if (i >= 0 && i < listSheetItem.size() - 1) {
                        textView.setBackgroundResource(R.drawable.action_sheet_middle);
                    } else {
                        textView.setBackgroundResource(R.drawable.action_sheet_bottom);
                    }
                } else {
                    if (i == 0) {
                        textView.setBackgroundResource(R.drawable.action_sheet_top);
                    } else if (i < listSheetItem.size() - 1) {
                        textView.setBackgroundResource(R.drawable.action_sheet_middle);
                    } else {
                        textView.setBackgroundResource(R.drawable.action_sheet_bottom);
                    }
                }
            }
        } else {
            textView.setBackgroundResource(R.drawable.action_sheet_edge);
            tvCancel.setBackgroundResource(R.drawable.action_sheet_edge);
            tvTitle.setBackgroundResource(R.color.colorActionSheetEdge);
            view.setBackgroundResource(R.color.colorActionSheetEdgeLineGray);
        }
        // 字体颜色
        textView.setTextColor(sheetItem.color);
        LinearLayout.LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        // 高度
        textView.setLayoutParams(params);
        textView.setMinimumHeight(getItemHeight());
        tvTitle.setMinimumHeight(STYLE != STYLE_IOS ? getItemHeight() : dip2px(20));
        textView.setLineSpacing(mLineSpacingExtra, mLineSpacingMultiplier);
        // 点击事件
        textView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null) {
                    listener.onClick(item);
                }
                dialog.dismiss();
            }
        });
        lLayoutItem.addView(textView);
        if (STYLE == STYLE_NORMAL) {
            view.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, (int) context.getResources().getDimension(R.dimen.dp_line_size)));
            lLayoutItem.addView(view);
        }
    }
}