# SpannableTextView **Repository Path**: applibgroup/SpannableTextView ## Basic Information - **Project Name**: SpannableTextView - **Description**: SpannableTextView is a custom TextView which lets you customize the styling of slice of your text or statment via Spannables, but without the hassle of having to deal directly with Spannable themselves. - **Primary Language**: Java - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-10-13 - **Last Updated**: 2022-01-03 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # SpannableTextView [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=applibgroup_SpannableTextView&metric=alert_status)](https://sonarcloud.io/dashboard?id=applibgroup_SpannableTextView) [![Build](https://github.com/applibgroup/SpannableTextView/actions/workflows/main.yml/badge.svg)](https://github.com/applibgroup/SpannableTextView/actions/workflows/main.yml) ## Introduction ###### SpannableTextView is a custom `TextView` which lets you customize the styling of SpannableStyles of your text or statment via `Spannables`, but without the hassle of having to deal directly with Spannable themselves. ## Source ###### The code in this repository was inspired from [milaptank/SpannableTextView - v1.0.0](https://github.com/milaptank/SpannableTextView). We are very thankful to milaptank. ## Screenshot ![Continuous, Discrete, Custom Java layout](Images/spannabletextview.png)                  ![Continuous, Discrete, Custom Java layout](Images/device.png)                  ## Installation In order to use the library, add the following line to your **root** gradle file(entry/build.gradle): ```groovy dependencies{ implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) implementation project(path: ':spannabletextview') testImplementation 'junit:junit:4.13' } ``` ​ ## Usage Generate the following style: ## Screenshot ![Continuous, Discrete, Custom Java layout](Images/style.png)                  With the code below: ``` Java stvMarksDown.addSlice(new SpannableStyles.Builder(this.getResourceManager() .getElement(ResourceTable.String_stvMarksDown).getString()) .backgroundColor(RgbPalette.parse(this.getResourceManager() .getElement(ResourceTable.Color_customized_burgundy).getString())) .textColor(Color.WHITE.getValue()) .setCornerRadius(13) .build()); stvMarksDown.display(); stvMarksDownText.addSlice(new SpannableStyles.Builder(this.getResourceManager() .getElement(ResourceTable.String_stMrksDTxt).getString()) .textColor(RgbPalette.parse(this.getResourceManager() .getElement(ResourceTable.Color_customized_darkblue).getString())) .style(Font.BOLD) .build()); stvMarksDownText.display(); ``` What kind of styles can I add? -------- Right now you can customize the style of your text by using the following methods, which internally get converted to the corresponding `spannableS` | SpannableTextView | Internal Span | | ------------- |:-------------:| | textSize | setTextSize() | | textColor | setTextColor() | | textSizeRelative | RelativeSizeSpan | | style | setTextFont() | | underline | setUnderline() | | strike | setStrikethrough() | What else can I do? -------- Once you've created and displayed your SpannableTextView, you can modify the text contents of each `SpannableStyles` individually. For example, if we want to change the `3.5/10` from the above example into `6/10`, we could do the following: ``` java { "name": "stvMarksDown", "value": " 6/10 " } ``` ## Support & extension Currently there is a limitation to set subscript,superscript,backgroundColor and ImageResource. So subscript,superscript,backgroundColor and ImageResource cannot be set from sample app to Spans. ### License ``` MIT License Copyright (c) 2017 milap tank Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ```