Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,20 @@ class AnimatedBottomBar @JvmOverloads constructor(
tabStyle.textSize
)

textMaxLines = attr.getInt(R.styleable.AnimatedBottomBar_abb_textMaxLines, tabStyle.textMaxLines)
textGravity = attr.getInt(R.styleable.AnimatedBottomBar_abb_textGravity, tabStyle.textGravity)

if(Build.VERSION.SDK_INT >= 23) {
textBreakStrategy = attr.getInt(
R.styleable.AnimatedBottomBar_abb_textBreakStrategy,
tabStyle.textBreakStrategy
)
textHyphenationFrequency = attr.getInt(
R.styleable.AnimatedBottomBar_abb_textHyphenationFrequency,
tabStyle.textHyphenationFrequency
)
}

// Icon
iconSize =
attr.getDimension(
Expand Down Expand Up @@ -962,6 +976,40 @@ class AnimatedBottomBar @JvmOverloads constructor(
applyTabStyle(BottomBarStyle.StyleUpdateType.TEXT)
}

var textMaxLines: Int
get() = tabStyle.textMaxLines
set(value) {
tabStyle.textMaxLines = value
applyTabStyle(BottomBarStyle.StyleUpdateType.TEXT)
}

var textGravity: Int
get() = tabStyle.textGravity
set(value) {
tabStyle.textGravity = value
applyTabStyle(BottomBarStyle.StyleUpdateType.TEXT)
}

var textHyphenationFrequency: Int
@RequiresApi(23)
get() = tabStyle.textHyphenationFrequency

@RequiresApi(23)
set(value) {
tabStyle.textHyphenationFrequency = value
applyTabStyle(BottomBarStyle.StyleUpdateType.TEXT)
}

var textBreakStrategy: Int
@RequiresApi(23)
get() = tabStyle.textBreakStrategy

@RequiresApi(23)
set(value) {
tabStyle.textBreakStrategy = value
applyTabStyle(BottomBarStyle.StyleUpdateType.TEXT)
}

// Icon
var iconSize
@Dimension
Expand Down
11 changes: 11 additions & 0 deletions library/src/main/java/nl/joery/animatedbottombar/BottomBarStyle.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package nl.joery.animatedbottombar

import android.annotation.SuppressLint
import android.graphics.Color
import android.graphics.Typeface
import android.graphics.text.LineBreaker
import android.text.Layout
import android.view.Gravity
import android.view.animation.Interpolator
import androidx.annotation.ColorInt
import androidx.annotation.Dimension
Expand All @@ -11,6 +15,9 @@ import nl.joery.animatedbottombar.utils.dpPx
import nl.joery.animatedbottombar.utils.spPx

object BottomBarStyle {
// Suppresses the warning on textBreakStrategy and textHyphenationFrequency.
// The values won't be used if API level < 23
@SuppressLint("NewApi")
data class Tab(
// Type
var selectedTabType: AnimatedBottomBar.TabType = AnimatedBottomBar.TabType.ICON,
Expand All @@ -34,6 +41,10 @@ object BottomBarStyle {
@StyleRes var textAppearance: Int = -1,
var typeface: Typeface = Typeface.DEFAULT,
var textSize: Int = 14.spPx,
var textMaxLines: Int = 1,
var textGravity: Int = Gravity.CENTER_HORIZONTAL,
var textBreakStrategy: Int = LineBreaker.BREAK_STRATEGY_SIMPLE,
var textHyphenationFrequency: Int = Layout.HYPHENATION_FREQUENCY_NONE,

// Icon
var iconSize: Int = 24.dpPx,
Expand Down
10 changes: 9 additions & 1 deletion library/src/main/java/nl/joery/animatedbottombar/TabView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ internal class TabView @JvmOverloads constructor(

textView = this
ellipsize = TextUtils.TruncateAt.END
isSingleLine = true
})

addView(BadgeView(context).apply {
Expand Down Expand Up @@ -287,6 +286,15 @@ internal class TabView @JvmOverloads constructor(
private fun updateText() {
textView.run {
typeface = style.typeface
maxLines = style.textMaxLines

if(Build.VERSION.SDK_INT >= 23) {
hyphenationFrequency = style.textHyphenationFrequency
breakStrategy = style.textBreakStrategy
}

gravity = style.textGravity

setTextSize(TypedValue.COMPLEX_UNIT_PX, style.textSize.toFloat())
}

Expand Down
20 changes: 20 additions & 0 deletions library/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,26 @@
<flag name="normal" value="0" />
</attr>
<attr name="abb_textSize" format="dimension" />

<attr name="abb_textMaxLines" format="integer" min="0"/>
<attr name="abb_textGravity" format="enum">
<enum name="start" value="0x00800003" />
<enum name="end" value="0x00800005" />
<enum name="center" value="0x01" />
</attr>

<attr name="abb_textBreakStrategy">
<enum name="simple" value="0" />
<enum name="high_quality" value="1" />
<enum name="balanced" value="2" />
</attr>

<attr name="abb_textHyphenationFrequency">
<enum name="none" value="0" />
<enum name="normal" value="1" />
<enum name="full" value="2" />
</attr>

<attr name="abb_iconSize" format="dimension" />

<!-- Badge -->
Expand Down