toggle label font weight according to m3

This commit is contained in:
sk 2023-10-08 12:49:29 +02:00
parent 98677cd307
commit f747d4c979
2 changed files with 18 additions and 5 deletions

View File

@ -1,9 +1,11 @@
package org.joinmastodon.android.ui.views;
import android.content.Context;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import java.util.function.IntConsumer;
import java.util.function.IntPredicate;
@ -45,9 +47,7 @@ public class TabBar extends LinearLayout{
listener.accept(v.getId());
if(v.getId()==selectedTabID)
return;
findViewById(selectedTabID).setSelected(false);
v.setSelected(true);
selectedTabID=v.getId();
selectTab(v.getId());
}
private boolean onChildLongClick(View v){
@ -60,8 +60,17 @@ public class TabBar extends LinearLayout{
}
public void selectTab(int id){
findViewById(selectedTabID).setSelected(false);
toggleSelected(selectedTabID, false);
selectedTabID=id;
findViewById(selectedTabID).setSelected(true);
toggleSelected(id, true);
}
private void toggleSelected(int selectedTabID, boolean selected){
LinearLayout tab=findViewById(selectedTabID);
tab.setSelected(selected);
View v=tab.findViewWithTag("label");
if(v instanceof TextView text){
text.setTypeface(Typeface.create(text.getTypeface(), selected ? Typeface.BOLD : Typeface.NORMAL));
}
}
}

View File

@ -51,6 +51,7 @@
android:layout_gravity="center_horizontal"
android:layout_marginTop="4dp"
android:textColor="@color/m3_on_surface_selector"
android:tag="label"
android:text="@string/sk_tab_home" />
</LinearLayout>
@ -91,6 +92,7 @@
android:textColor="@color/m3_on_surface_selector"
android:layout_gravity="center_horizontal"
android:layout_marginTop="4dp"
android:tag="label"
android:text="@string/sk_tab_search" />
</LinearLayout>
@ -149,6 +151,7 @@
android:layout_gravity="center_horizontal"
android:layout_marginTop="4dp"
android:textColor="@color/m3_on_surface_selector"
android:tag="label"
android:text="@string/sk_tab_notifications" />
</LinearLayout>
@ -195,6 +198,7 @@
android:layout_gravity="center_horizontal"
android:layout_marginTop="4dp"
android:textColor="@color/m3_on_surface_selector"
android:tag="label"
android:text="@string/sk_tab_profile" />
</LinearLayout>