我試圖在 android studio 的 tablayout 中使用白點作為選項卡圖示。
我使用網上的一個例子來定義點:
ic_tab_default.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:innerRadius="0dp"
android:shape="ring"
android:thickness="24dp"
android:useLevel="false">
<solid android:color="@android:color/white"/>
</shape>
我將它添加到我的 tablayout 中以預覽它 mainactivity.xml:
<com.google.android.material.tabs.TabLayout
android:id="@ id/mainTablayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/black"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:tabGravity="center"
app:tabIconTint="@color/white"
tools:ignore="SpeakableTextPresentCheck">
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:icon="@drawable/tab_selected" />
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:icon="@drawable/tab_default" />
</com.google.android.material.tabs.TabLayout>
<androidx.viewpager2.widget.ViewPager2
android:id="@ id/mainViewPager"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/mainTablayout" />

然而,我添加后它變成了一個正方形,我怎樣才能讓它變成一個點?
uj5u.com熱心網友回復:
也許這會奏效
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="10dp"
android:height="10dp"
android:tint="#ffffff"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#ffffff"
android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM10,9z" />
</vector>
uj5u.com熱心網友回復:
tab_default.xml
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="oval"
xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF"/>
</shape>
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/375835.html
