A customizable Android View that displays main text with subscript and superscript — perfect for chemical formulas, mathematical expressions, and scientific notations. Offers full control over colors, sizes, margins, and positioning.
- Features
- Demo
- Getting Started
- Usage
- Attributes
- API Reference
- Compatibility
- Troubleshooting
- Roadmap
- Why This Project Matters to Employers
- Credits
- Feedback & Contributions
- License
- Dual script support: Display both subscript and superscript alongside the main text.
- Full style control: Configure text colors, sizes, margins, and offsets independently.
- Custom fonts: Apply different typefaces to main, subscript, and superscript text.
- Lightweight: No external dependencies, minimal performance overhead.
- Easy integration: Use directly in XML or modify at runtime in Java/Kotlin.
Copy the TextScriptView class and any required resources into your project, or include it as a module if you maintain it as a separate library.
In your module build.gradle (AGP 8+):
android {
namespace 'com.example.app' // Replace with your app's package
compileSdk 34
defaultConfig {
minSdk 21
targetSdk 34
versionCode 1
versionName "1.0"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
}<com.hilfritz.library.textscriptview.TextScriptView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:normalText="Bicarbonate - HC"
app:subText="3"
app:normalTextColor="@color/black"
app:subTextColor="@color/black"
android:layout_marginTop="@dimen/margin_d"
app:normalBetweenScriptMargin="1dp" />TextScriptView textScriptView = findViewById(R.id.textScriptView);
textScriptView.setText("E = MC");
textScriptView.setSuperScriptText("2");
textScriptView.setTextColor(R.color.navy);
textScriptView.setSubScriptTextColor(R.color.red);
textScriptView.setSuperScriptTextColor(R.color.black);
// Apply custom typeface
textScriptView.getTextView().setTypeface(FontCache.get(FontCache.FONT_GOTCHAGOTHIC_LIGHT, this));
textScriptView.getSuperscriptTextView().setTypeface(FontCache.get(FontCache.FONT_GOTCHAGOTHIC_LIGHT, this));
textScriptView.getSubscriptTextView().setTypeface(FontCache.get(FontCache.FONT_GOTCHAGOTHIC_LIGHT, this));| Attribute | Description |
|---|---|
normalText |
Main text content |
subText |
Subscript text content |
superText |
Superscript text content |
normalTextColor |
Color resource for main text |
subTextColor |
Color resource for subscript text |
superTextColor |
Color resource for superscript text |
normalTextSize |
Size resource for main text |
subTextSize |
Size resource for subscript text |
superTextSize |
Size resource for superscript text |
normalBetweenScriptMargin |
Horizontal spacing between main text and scripts |
moveSuperUp |
Moves superscript upward (dimension resource) |
moveSubDown |
Moves subscript downward (dimension resource) |
| Method | Description |
|---|---|
getTextView() |
Returns the main TextView |
getSubscriptTextView() |
Returns the subscript TextView |
getSuperscriptTextView() |
Returns the superscript TextView |
- minSdk: 21+
- compile/target: API 34 recommended
- Gradle: 8.5+
- Android Gradle Plugin: 8.x
- JDK: 17–19
- Namespace not specified → Add
namespaceinside yourandroid {}block. android:exportederror → Addandroid:exportedto components with<intent-filter>when targeting Android 12+.- Font not applied → Ensure typeface is set on all three text views (main, subscript, superscript).
- Kotlin extensions for easier usage
- XML preview support for scripts
- Animation support for script text changes
Building TextScriptView demonstrates:
- Custom View expertise: Creating reusable UI components beyond stock widgets.
- Attention to detail: Managing typography, spacing, and visual consistency.
- API design skills: Clear, intuitive attributes and public methods.
- Cross-functional thinking: Supports both design aesthetics and developer ergonomics.
- Author: Hilfritz Camallere
- Purpose: Simplify displaying script-based text in Android apps.
Issues and pull requests are welcome!
Open an Issue | Submit a Pull Request
Choose a license (MIT or Apache 2.0 recommended).
