Java Code Examples for android.widget.TextView#setBackgroundDrawable()

The following examples show how to use android.widget.TextView#setBackgroundDrawable() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
private void initView(Context context) {
    mTextView = new ExTextView(context);
    mClickToShow = new TextView(context);

    mTextView.setTextSize(textSize);
    mTextView.setTextColor(textColor);
    mTextView.setMaxLines(showLine);

    mClickToShow.setBackgroundDrawable(getResources().getDrawable(R.drawable.selector_tx_show_more));
    mClickToShow.setTextSize(textSize);
    mClickToShow.setTextColor(getResources().getColor(R.color.nickname));
    mClickToShow.setText(clickText);

    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    params.topMargin = UIHelper.dipToPx(10f);
    mClickToShow.setLayoutParams(params);
    mClickToShow.setOnClickListener(this);

    setOrientation(VERTICAL);
    addView(mTextView);
    addView(mClickToShow);
}
 
Example 2
public void addTextTab(final int position, String title) {
    TextView tab = new TextView(getContext());
    tab.setText(title);
    tab.setFocusable(true);
    tab.setGravity(Gravity.CENTER);
    tab.setSingleLine();
    tab.setTextColor(0xffffffff);
    tab.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    tab.setTypeface(Typeface.DEFAULT_BOLD);
    tab.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.ACTION_BAR_PICKER_SELECTOR_COLOR, 0));

    tab.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            didSelectTab(position);
        }
    });
    addView(tab);
    LayoutParams layoutParams = (LayoutParams)tab.getLayoutParams();
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    layoutParams.width = 0;
    layoutParams.weight = 50;
    tab.setLayoutParams(layoutParams);

    tabCount++;
}
 
Example 3
public StickerSetGroupInfoCell(Context context) {
    super(context);
    setOrientation(VERTICAL);

    TextView infoTextView = new TextView(context);
    infoTextView.setTextColor(Theme.getColor(Theme.key_chat_emojiPanelTrendingDescription));
    infoTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    infoTextView.setText(LocaleController.getString("GroupStickersInfo", R.string.GroupStickersInfo));
    addView(infoTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 17, 4, 17, 0));

    addButton = new TextView(context);
    addButton.setPadding(AndroidUtilities.dp(17), 0, AndroidUtilities.dp(17), 0);
    addButton.setGravity(Gravity.CENTER);
    addButton.setTextColor(Theme.getColor(Theme.key_featuredStickers_buttonText));
    addButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    addButton.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    addButton.setBackgroundDrawable(Theme.createSimpleSelectorRoundRectDrawable(AndroidUtilities.dp(4), Theme.getColor(Theme.key_featuredStickers_addButton), Theme.getColor(Theme.key_featuredStickers_addButtonPressed)));
    addButton.setText(LocaleController.getString("ChooseStickerSet", R.string.ChooseStickerSet).toUpperCase());
    addView(addButton, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, 28, Gravity.TOP | Gravity.LEFT, 17, 10, 14, 8));
}
 
Example 4
public void addTextTab(final int position, String title)
{
    TextView tab = new TextView(getContext());
    tab.setText(title);
    tab.setFocusable(true);
    tab.setGravity(Gravity.CENTER);
    tab.setSingleLine();
    tab.setTextColor(0xffffffff);
    tab.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    tab.setTypeface(Typeface.DEFAULT_BOLD);
    tab.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.ACTION_BAR_PICKER_SELECTOR_COLOR, 0));

    tab.setOnClickListener(v -> didSelectTab(position));
    addView(tab);
    LayoutParams layoutParams = (LayoutParams) tab.getLayoutParams();
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    layoutParams.width = 0;
    layoutParams.weight = 50;
    tab.setLayoutParams(layoutParams);

    tabCount++;
}
 
Example 5
Source Project: YiBo   File: CommentHolder.java    License: Apache License 2.0 6 votes vote down vote up
public CommentHolder(View convertView) {
	if (convertView == null) {
		throw new IllegalArgumentException("convertView is null!");
	}
	context = convertView.getContext();
	ivProfilePicture = (ImageView) convertView.findViewById(R.id.ivProfilePicture);
	tvScreenName = (TextView) convertView.findViewById(R.id.tvScreenName);
	ivVerify = (ImageView) convertView.findViewById(R.id.ivVerify);
	tvCreatedAt = (TextView) convertView.findViewById(R.id.tvCreatedAt);
	tvText = (TextView) convertView.findViewById(R.id.tvText);		
	tvReplyText = (TextView) convertView.findViewById(R.id.tvReplyText);

	//设置主题 
       Theme theme = ThemeUtil.createTheme(context);
       tvScreenName.setTextColor(theme.getColor("highlight"));
       ivVerify.setImageDrawable(GlobalResource.getIconVerification(context));
       tvText.setTextColor(theme.getColor("content"));
       tvText.setLinkTextColor(theme.getColorStateList("selector_text_link"));
       tvReplyText.setTextColor(theme.getColor("quote"));
       tvReplyText.setLinkTextColor(theme.getColorStateList("selector_text_link"));
	tvReplyText.setBackgroundDrawable(GlobalResource.getBgRetweetFrame(context));
	tvReplyText.setPadding(theme.dip2px(10), theme.dip2px(12), 
        theme.dip2px(10), theme.dip2px(6));
	
	reset();
}
 
Example 6
public StickerSetGroupInfoCell(Context context) {
    super(context);
    setOrientation(VERTICAL);

    TextView infoTextView = new TextView(context);
    infoTextView.setTextColor(Theme.getColor(Theme.key_chat_emojiPanelTrendingDescription));
    infoTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    infoTextView.setText(LocaleController.getString("GroupStickersInfo", R.string.GroupStickersInfo));
    addView(infoTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 17, 4, 17, 0));

    addButton = new TextView(context);
    addButton.setPadding(AndroidUtilities.dp(17), 0, AndroidUtilities.dp(17), 0);
    addButton.setGravity(Gravity.CENTER);
    addButton.setTextColor(Theme.getColor(Theme.key_featuredStickers_buttonText));
    addButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    addButton.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    addButton.setBackgroundDrawable(Theme.createSimpleSelectorRoundRectDrawable(AndroidUtilities.dp(4), Theme.getColor(Theme.key_featuredStickers_addButton), Theme.getColor(Theme.key_featuredStickers_addButtonPressed)));
    addButton.setText(LocaleController.getString("ChooseStickerSet", R.string.ChooseStickerSet).toUpperCase());
    addView(addButton, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, 28, Gravity.TOP | Gravity.LEFT, 17, 10, 14, 8));
}
 
Example 7
Source Project: ClockView   File: SingleLineFlowLayout.java    License: Apache License 2.0 5 votes vote down vote up
private TextView initItemView(String text) {
    TextView textView = new TextView(getContext());
    textView.setText(text);
    textView.setPadding(10,10,10,10);
    textView.setBackgroundDrawable(getResources().getDrawable(R.drawable.btn_red_boder_shape));
    return textView;
}
 
Example 8
private void initView() {
    //标题:SDK 调试模式选择
    TextView debugModeTitle = findViewById(R.id.sensors_analytics_debug_mode_title);
    debugModeTitle.setText("SDK 调试模式选择");

    //取消
    TextView debugModeCancel = findViewById(R.id.sensors_analytics_debug_mode_cancel);
    debugModeCancel.setText("取消");
    debugModeCancel.setOnClickListener(this);

    //开启调试模式(不导入数据)
    TextView debugModeOnly = findViewById(R.id.sensors_analytics_debug_mode_only);
    debugModeOnly.setText("开启调试模式(不导入数据)");
    debugModeOnly.setOnClickListener(this);

    //"开启调试模式(导入数据)"
    TextView debugModeTrack = findViewById(R.id.sensors_analytics_debug_mode_track);
    debugModeTrack.setText("开启调试模式(导入数据)");
    debugModeTrack.setOnClickListener(this);

    String msg = "调试模式已关闭";
    if (currentDebugMode == SensorsDataAPI.DebugMode.DEBUG_ONLY) {
        msg = "当前为 调试模式(不导入数据)";
    } else if (currentDebugMode == SensorsDataAPI.DebugMode.DEBUG_AND_TRACK) {
        msg = "当前为 测试模式(导入数据)";
    }
    TextView debugModeMessage = findViewById(R.id.sensors_analytics_debug_mode_message);
    debugModeMessage.setText(msg);

    //设置按钮点击效果
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        debugModeCancel.setBackground(getDrawable());
        debugModeOnly.setBackground(getDrawable());
        debugModeTrack.setBackground(getDrawable());
    } else {
        debugModeCancel.setBackgroundDrawable(getDrawable());
        debugModeOnly.setBackgroundDrawable(getDrawable());
        debugModeTrack.setBackgroundDrawable(getDrawable());
    }
}
 
Example 9
public PickerBottomLayoutViewer(Context context, boolean darkTheme) {
    super(context);
    isDarkTheme = darkTheme;

    setBackgroundColor(isDarkTheme ? 0xff1a1a1a : 0xffffffff);

    cancelButton = new TextView(context);
    cancelButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    cancelButton.setTextColor(isDarkTheme ? 0xffffffff : 0xff19a7e8);
    cancelButton.setGravity(Gravity.CENTER);
    cancelButton.setBackgroundDrawable(Theme.createSelectorDrawable(isDarkTheme ? Theme.ACTION_BAR_PICKER_SELECTOR_COLOR : Theme.ACTION_BAR_AUDIO_SELECTOR_COLOR, 0));
    cancelButton.setPadding(AndroidUtilities.dp(20), 0, AndroidUtilities.dp(20), 0);
    cancelButton.setText(LocaleController.getString("Cancel", R.string.Cancel).toUpperCase());
    cancelButton.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    addView(cancelButton, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT));

    doneButton = new TextView(context);
    doneButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    doneButton.setTextColor(isDarkTheme ? 0xffffffff : 0xff19a7e8);
    doneButton.setGravity(Gravity.CENTER);
    doneButton.setBackgroundDrawable(Theme.createSelectorDrawable(isDarkTheme ? Theme.ACTION_BAR_PICKER_SELECTOR_COLOR : Theme.ACTION_BAR_AUDIO_SELECTOR_COLOR, 0));
    doneButton.setPadding(AndroidUtilities.dp(20), 0, AndroidUtilities.dp(20), 0);
    doneButton.setText(LocaleController.getString("Send", R.string.Send).toUpperCase());
    doneButton.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    addView(doneButton, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.RIGHT));

    doneButtonBadgeTextView = new TextView(context);
    doneButtonBadgeTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    doneButtonBadgeTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13);
    doneButtonBadgeTextView.setTextColor(0xffffffff);
    doneButtonBadgeTextView.setGravity(Gravity.CENTER);
    doneButtonBadgeTextView.setBackgroundResource(isDarkTheme ? R.drawable.photobadge : R.drawable.bluecounter);
    doneButtonBadgeTextView.setMinWidth(AndroidUtilities.dp(23));
    doneButtonBadgeTextView.setPadding(AndroidUtilities.dp(8), 0, AndroidUtilities.dp(8), AndroidUtilities.dp(1));
    addView(doneButtonBadgeTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, 23, Gravity.TOP | Gravity.RIGHT, 0, 0, 7, 0));
}
 
Example 10
public void setButtons(TLRPC.TL_replyKeyboardMarkup buttons) {
    botButtons = buttons;
    container.removeAllViews();
    buttonViews.clear();
    scrollView.scrollTo(0, 0);

    if (buttons != null && botButtons.rows.size() != 0) {
        isFullSize = !buttons.resize;
        buttonHeight = !isFullSize ? 42 : (int) Math.max(42, (panelHeight - AndroidUtilities.dp(30) - (botButtons.rows.size() - 1) * AndroidUtilities.dp(10)) / botButtons.rows.size() / AndroidUtilities.density);
        for (int a = 0; a < buttons.rows.size(); a++) {
            TLRPC.TL_keyboardButtonRow row = buttons.rows.get(a);

            LinearLayout layout = new LinearLayout(getContext());
            layout.setOrientation(LinearLayout.HORIZONTAL);
            container.addView(layout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, buttonHeight, 15, a == 0 ? 15 : 10, 15, a == buttons.rows.size() - 1 ? 15 : 0));

            float weight = 1.0f / row.buttons.size();
            for (int b = 0; b < row.buttons.size(); b++) {
                TLRPC.KeyboardButton button = row.buttons.get(b);
                TextView textView = new TextView(getContext());
                textView.setTag(button);
                textView.setTextColor(Theme.getColor(Theme.key_chat_botKeyboardButtonText));
                textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
                textView.setGravity(Gravity.CENTER);
                textView.setBackgroundDrawable(Theme.createSimpleSelectorRoundRectDrawable(AndroidUtilities.dp(4), Theme.getColor(Theme.key_chat_botKeyboardButtonBackground), Theme.getColor(Theme.key_chat_botKeyboardButtonBackgroundPressed)));
                textView.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0);
                textView.setText(Emoji.replaceEmoji(button.text, textView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(16), false));
                layout.addView(textView, LayoutHelper.createLinear(0, LayoutHelper.MATCH_PARENT, weight, 0, 0, b != row.buttons.size() - 1 ? 10 : 0, 0));
                textView.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        delegate.didPressedButton((TLRPC.KeyboardButton) v.getTag());
                    }
                });
                buttonViews.add(textView);
            }
        }
    }
}
 
Example 11
Source Project: YuanNewsForAndroid   File: PromptDialog.java    License: Apache License 2.0 4 votes vote down vote up
private void setBtnBackground(final TextView btnOk) {
    btnOk.setTextColor(createColorStateList(getContext().getResources().getColor(getColorResId(mDialogType)),
            getContext().getResources().getColor(R.color.color_dialog_gray)));
    btnOk.setBackgroundDrawable(getContext().getResources().getDrawable(getSelBtn(mDialogType)));
}
 
Example 12
@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.fragment_sign_email, container, false);

        TextView buttonCotinueText = (TextView) v.findViewById(R.id.button_continue_text);
        StateListDrawable states = SelectorFactory.get(ActorSDK.sharedActor().style.getMainColor(), getActivity());
        buttonCotinueText.setBackgroundDrawable(states);
        buttonCotinueText.setTypeface(Fonts.medium());
        buttonCotinueText.setTextColor(ActorSDK.sharedActor().style.getTextPrimaryInvColor());

        keyboardHelper = new KeyboardHelper(getActivity());

        initView(v);

//        Get domain logo

//        logoActor = ActorSystem.system().actorOf(Props.create(LogoActor.class, new ActorCreator<LogoActor>() {
//            @Override
//            public LogoActor create() {
//                return new LogoActor();
//            }
//        }), "actor/logo_actor");
//
//        logoActor.send(new LogoActor.AddCallback(new LogoActor.LogoCallBack() {
//            @Override
//            public void onDownloaded(final Drawable logoDrawable) {
//                getActivity().runOnUiThread(new Runnable() {
//                    @Override
//                    public void run() {
//                        if (logoDrawable != null) {
//                            logo.setImageDrawable(logoDrawable);
//                            logo.measure(0, 0);
//                            expand(logo, logo.getMeasuredHeight());
//                        } else {
//                            expand(logo, 0);
//                        }
//                    }
//                });
//            }
//        }));
        v.findViewById(R.id.divider).setBackgroundColor(style.getDividerColor());
        setTosAndPrivacy((TextView) v.findViewById(R.id.disclaimer));

        return v;
    }
 
Example 13
Source Project: MHViewer   File: GalleryDetailScene.java    License: Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
private void bindTags(GalleryChapterGroup[] tagGroups) {
    Context context = getContext2();
    LayoutInflater inflater = getLayoutInflater2();
    Resources resources = getResources2();
    if (null == context || null == inflater || null == resources || null == mTags || null == mNoTags) {
        return;
    }

    mTags.removeViews(1, mTags.getChildCount() - 1);
    if (tagGroups == null || tagGroups.length == 0) {
        mNoTags.setVisibility(View.VISIBLE);
        return;
    } else {
        mNoTags.setVisibility(View.GONE);
    }

    int colorTag = AttrResources.getAttrColor(context, R.attr.tagBackgroundColor);
    int colorName = AttrResources.getAttrColor(context, R.attr.tagGroupBackgroundColor);
    for (GalleryChapterGroup tg : tagGroups) {
        LinearLayout ll = (LinearLayout) inflater.inflate(R.layout.gallery_tag_group, mTags, false);
        ll.setOrientation(LinearLayout.HORIZONTAL);
        mTags.addView(ll);
        TextView tgName = (TextView) inflater.inflate(R.layout.item_gallery_tag, ll, false);
        ll.addView(tgName);
        tgName.setText(tg.getGroupName());
        tgName.setBackgroundDrawable(new RoundSideRectDrawable(colorName));

        AutoWrapLayout awl = new AutoWrapLayout(context);
        ll.addView(awl, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        for (int j = 0, z = tg.size(); j < z; j++) {
            TextView tag = (TextView) inflater.inflate(R.layout.item_gallery_tag, awl, false);
            awl.addView(tag);
            GalleryChapter chapter = tg.getChapterList().get(j);
            tag.setText(chapter.getTitle());
            tag.setBackgroundDrawable(new RoundSideRectDrawable(chapter.getRead() ? colorName : colorTag));
            tag.setTag(R.id.tag, chapter);
            tag.setOnClickListener(this);
            tag.setOnLongClickListener(this);
        }
    }
}
 
Example 14
Source Project: WeekCalendar   File: WeekCalendar.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public View getItemView(final int position, View convertView, final ViewHolder viewHolder) {
    final CalendarData calendar = (CalendarData) getItem(position);
    final TextView dayView = (TextView) viewHolder.getView(R.id.tv_calendar_day);
    final TextView weekView = (TextView) viewHolder.getView(R.id.tv_calendar_week);
    ImageView corner_mark_iv = (ImageView) viewHolder.getView(R.id.corner_mark_iv);
    weekView.setText(WeekCalendarUtil.getWeekString(mContext).get(position));
    dayView.setTextSize(daysTextSize);
    weekView.setTextSize(weekTextSize);
    weekView.setBackgroundColor(weekBackgroundColor);
    if (isCornerMark) {
        corner_mark_iv.setBackgroundDrawable(cornerMarkBg);
    } else {
        corner_mark_iv.setVisibility(View.GONE);
    }
    if (!hideTodayName) {
        if (!calendar.isSameDay(today)) {
            dayView.setText(String.valueOf(calendar.day));
        } else {
            dayView.setText(String.valueOf("今"));
        }
    } else {
        dayView.setText(String.valueOf(calendar.day));
    }
    if (calendar.isSameDay(theDayOfSelected)) {//被选中的日期是白的
        dayView.setTextColor(daysSelectedTextColor);
        dayView.setBackgroundDrawable(daysSelectedBackground);
    } else if (calendar.isLastMonthDay || calendar.isNextMonthDay) {//上一个月、下一个月的日期是灰色的
        dayView.setTextColor(Color.LTGRAY);
        dayView.setBackgroundDrawable(null);
    } else if (calendar.isSameDay(today)) {//当天的日期是橘黄色的
        dayView.setTextColor(todayTextColor);
        dayView.setText("今");
        dayView.setBackgroundDrawable(null);
    } else {
        dayView.setBackgroundDrawable(null);
        dayView.setTextColor(weekTextColor);
    }

    if (selectDateList != null) {
        for (int i = 0; i < selectDateList.size(); i++) {
            String dateStr = selectDateList.get(i);
            String[] dates = dateStr.split("-");
            CalendarData cd = new CalendarData();
            cd.year = Integer.parseInt(dates[0]);
            cd.month = Integer.parseInt(dates[1]);
            cd.day = Integer.parseInt(dates[2]);
            if (calendar.isSameDay(cd)) {
                corner_mark_iv.setVisibility(View.VISIBLE);
                break;
            } else {
                corner_mark_iv.setVisibility(View.GONE);
            }
        }
    }

    //如果设置了回调,则设置点击事件
    dayView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            theDayOfSelected = datas.get(position);
            theDayForShow = datas.get(position);
            notifyDataSetChanged();
            if (listener != null) {
                listener.onDateClick(getTheDayOfSelected());
            }
        }
    });
    return convertView;
}
 
Example 15
Source Project: EhViewer   File: GalleryDetailScene.java    License: Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
private void bindTags(GalleryTagGroup[] tagGroups) {
    Context context = getContext2();
    LayoutInflater inflater = getLayoutInflater2();
    Resources resources = getResources2();
    if (null == context || null == inflater || null == resources || null == mTags || null == mNoTags) {
        return;
    }

    mTags.removeViews(1, mTags.getChildCount() - 1);
    if (tagGroups == null || tagGroups.length == 0) {
        mNoTags.setVisibility(View.VISIBLE);
        return;
    } else {
        mNoTags.setVisibility(View.GONE);
    }

    EhTagDatabase ehTags = Settings.getShowTagTranslations() ? EhTagDatabase.getInstance(context) : null;
    int colorTag = AttrResources.getAttrColor(context, R.attr.tagBackgroundColor);
    int colorName = AttrResources.getAttrColor(context, R.attr.tagGroupBackgroundColor);
    for (GalleryTagGroup tg : tagGroups) {
        LinearLayout ll = (LinearLayout) inflater.inflate(R.layout.gallery_tag_group, mTags, false);
        ll.setOrientation(LinearLayout.HORIZONTAL);
        mTags.addView(ll);

        String readableTagName = null;
        if (ehTags != null) {
            readableTagName = ehTags.getTranslation("n:" + tg.groupName);
        }

        TextView tgName = (TextView) inflater.inflate(R.layout.item_gallery_tag, ll, false);
        ll.addView(tgName);
        tgName.setText(readableTagName != null ? readableTagName : tg.groupName);
        tgName.setBackgroundDrawable(new RoundSideRectDrawable(colorName));

        String prefix = EhTagDatabase.namespaceToPrefix(tg.groupName);
        if (prefix == null) {
            prefix = "";
        }

        AutoWrapLayout awl = new AutoWrapLayout(context);
        ll.addView(awl, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        for (int j = 0, z = tg.size(); j < z; j++) {
            TextView tag = (TextView) inflater.inflate(R.layout.item_gallery_tag, awl, false);
            awl.addView(tag);
            String tagStr = tg.getTagAt(j);

            String readableTag = null;
            if (ehTags != null) {
                readableTag = ehTags.getTranslation(prefix + tagStr);
            }

            tag.setText(readableTag != null ? readableTag : tagStr);
            tag.setBackgroundDrawable(new RoundSideRectDrawable(colorTag));
            tag.setTag(R.id.tag, tg.groupName + ":" + tagStr);
            tag.setOnClickListener(this);
            tag.setOnLongClickListener(this);
        }
    }
}
 
Example 16
public void addTabWithCounter(final int position, View view)
{
    RelativeLayout tab = new RelativeLayout(getContext());
    tab.setFocusable(true);

    tabsContainer.addView(tab, FeaturedSettings.tabSettings.tabsShouldExpand ? expandedTabLayoutParams : defaultTabLayoutParams);
    view.setBackgroundResource(btnBgRes);
    view.setOnClickListener(v ->
    {
        if (position == pager.getCurrentItem())
        {
            if (delegate != null)
                delegate.onTabClick();
        }
        else
        {
            if (pager != null)
                pager.setCurrentItem(position);
        }
    });

    tab.addView(view, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    tab.setSelected(position == currentPosition);

    TextView textView = new TextView(getContext());
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, FeaturedSettings.tabSettings.chatsTabCounterSize);
    textView.setTextColor(Theme.getColor(Theme.key_dialogBadgeText));
    textView.setGravity(Gravity.CENTER);

    GradientDrawable shape = new GradientDrawable();
    shape.setShape(GradientDrawable.RECTANGLE);
    shape.setCornerRadius(AndroidUtilities.dp(32));
    //noinspection deprecation
    textView.setBackgroundDrawable(shape);
    textView.setMinWidth(AndroidUtilities.dp(18));

    textView.setPadding(AndroidUtilities.dp(FeaturedSettings.tabSettings.chatsTabCounterSize > 10 ? FeaturedSettings.tabSettings.chatsTabCounterSize - 7 : 4), 0,
            AndroidUtilities.dp(FeaturedSettings.tabSettings.chatsTabCounterSize > 10 ? FeaturedSettings.tabSettings.chatsTabCounterSize - 7 : 4), 0);
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    params.setMargins(AndroidUtilities.dp(3), AndroidUtilities.dp(5), AndroidUtilities.dp(3), AndroidUtilities.dp(5));
    params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    tab.addView(textView, params);
}
 
Example 17
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Intent intent=getIntent();
    int port=intent.getIntExtra("remotePort",0);
    if(port>0){
        try {
            context=new TransmitClient(port);
        } catch (IOException e) {
            finish();
        }
    }else context=new DefaultScriptContext();
    if(editor==null){
        setContentView(R.layout.main);
        editor = findViewById(R.id.editor);
        psBar = findViewById(R.id.ps_bar);
        for (String text : ps) {
            StateListDrawable sd = new StateListDrawable();
            sd.addState(new int[]{android.R.attr.state_pressed}, new ColorDrawable(0x88000088));
            sd.addState(new int[]{0}, new ColorDrawable(0x00ffffff));
            TextView btn = new TextView(this);
            btn.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
            btn.setTextColor(Color.WHITE);
            btn.setTextSize(20);
            int pd = 20;
            btn.setPadding(pd, pd / 2, pd, pd / 4);
            btn.setText(text);
            btn.setBackgroundDrawable(sd);
            btn.setOnClickListener(v -> {
                editor.paste(text);
            });
            psBar.addView(btn);
        }
        editor.addNames(PRIMITIVE_TYPES);
        context.addToLua("context", this);
        configScriptContext();
    }

    Uri uri=intent.getData();
    String file=null;
    if(uri!=null){
        if("file".equals(uri.getScheme())){
            String path = uri.getPath();
            if(path!=null){
                file=new File(path).getAbsolutePath();
            }
        }
    }else if(editor.lastFile()==null){
        file=new File(getPreferences(0).getString(LAST,
                new File(Environment.getExternalStorageDirectory().getPath(),"test.lua").getPath())).getAbsolutePath();
    }
    if (Build.VERSION.SDK_INT>=23){
        requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE,Manifest.permission.READ_EXTERNAL_STORAGE},0);
    }
    loadFile(file);
    new Thread(()->{
        LibLoader.extractLibs(this, BuildConfig.VERSION_CODE);
    }).start();
}
 
Example 18
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_sign_phone, container, false);
    v.setBackgroundColor(ActorSDK.sharedActor().style.getMainBackgroundColor());
    TextView buttonContinue = (TextView) v.findViewById(R.id.button_continue_text);
    StateListDrawable states = SelectorFactory.get(ActorSDK.sharedActor().style.getMainColor(), getActivity());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        buttonContinue.setBackground(states);
    } else {
        buttonContinue.setBackgroundDrawable(states);
    }
    buttonContinue.setTextColor(ActorSDK.sharedActor().style.getTextPrimaryInvColor());
    buttonContinue.setTypeface(Fonts.medium());
    ((TextView) v.findViewById(R.id.button_why)).setTypeface(Fonts.medium());
    ((TextView) v.findViewById(R.id.button_why)).setTextColor(ActorSDK.sharedActor().style.getMainColor());

    keyboardHelper = new KeyboardHelper(getActivity());

    initView(v);

    countryDb = Countries.getInstance();

    String deviceCountry = Devices.getDeviceCountry();
    if (!TextUtils.isEmpty(deviceCountry)) {
        Country country = countryDb.getCountryByShortName(deviceCountry);
        setCountryName(country);
        if (country != null) {
            countryCodeEditText.setText(country.phoneCode);
            focusPhone();
        } else {
            focusCode();
        }
    } else {
        setCountryName(null);
        countryCodeEditText.setText("");
        focusCode();
    }
    v.findViewById(R.id.divider).setBackgroundColor(style.getDividerColor());
    setTosAndPrivacy((TextView) v.findViewById(R.id.disclaimer));

    return v;
}
 
Example 19
private void setTitles(Context context, String[] titles, int leftdrawable, int middrawable, int rightdrawable, int textsize, float borderwidth, final boolean smoothScroll)
{
    int length = titles.length;
    this.textViews = new TextView[titles.length];
    // 循环,根据标题栏动态生成TextView来显示标题,每个标题栏的宽度比例为1:1,其中的内容居中。
    for(int i = 0; i < length; i++)
    {
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0,LayoutParams.MATCH_PARENT);
        params.weight = 1;
        params.gravity = Gravity.CENTER;
        final int index = i;
        TextView textView = new TextView(context);
        textView.setText(titles[i]);
        textView.setTextSize(textsize);
        textView.setGravity(Gravity.CENTER);
        textViews[i] = textView;
        textViews[i].setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                viewPager.setCurrentItem(index, smoothScroll);
                if(onTitleClickListener != null)
                {
                    onTitleClickListener.onTitleClick(v);
                }
            }
        });
        if(i == 0)
        {
            textView.setBackgroundDrawable(context.getResources().getDrawable(leftdrawable));
            params.setMargins(0, 0, 0, 0);
        }
        else if(i == length - 1)
        {
            textView.setBackgroundDrawable(context.getResources().getDrawable(rightdrawable));
            params.setMargins(-dip2px(context, borderwidth), 0, 0, 0);
        }
        else
        {
            textView.setBackgroundDrawable(context.getResources().getDrawable(middrawable));
            params.setMargins(-dip2px(context, borderwidth), 0, 0, 0);
        }

        titleLayout.addView(textView, params);
    }
}
 
Example 20
Source Project: LotteryTrend   File: TrendActivity.java    License: Apache License 2.0 2 votes vote down vote up
/***
 * 改变底部选号选中和未被选中的背景色
 * @param tv TextView
 * @param redId drawble中的资源id
 */
private void changeSelectColorNumber(TextView tv,int redId) {
    tv.setBackgroundDrawable(getResources().getDrawable(redId));
}