因此,我有一个自定义的TabLayout,其中带有文本,并在其下方有一个圆形的黑点,以向用户显示他们需要单击它。因此,“我的布局”没有任何viewpager。我尝试了通知badge,但在tablayout中不起作用。
MainClass.java
public class MainActivity extends AppCompatActivity {
TabLayout tabLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tabLayout = findViewById(R.id.tablayout);
View view = (FrameLayout)LayoutInflater.from(this).inflate(R.layout.custom_layout, null);
TextView tv = (TextView) view.findViewById(R.id.textview);
tv.setText("This is cool");
tabLayout.addTab(tabLayout.newTab().setCustomView(view));
}
}
cusotm_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:id="@+id/textview"
android:text="SOmetext "
android:layout_height="wrap_content"
android:textColor="@color/colorPrimaryDark"
android:layout_gravity="center" />
<ImageView
android:layout_width="100dp"
android:src="@drawable/bg_card_elements"
android:id="@+id/imageview"
android:layout_gravity="bottom|center"
android:layout_height="100dp">
</ImageView>
</FrameLayout>
您的textview隐藏在imageview的后面,因此不显示。
像这样切换图像视图和文本视图
cusotm_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="100dp"
android:src="@drawable/bg_card_elements"
android:id="@+id/imageview"
android:layout_gravity="bottom|center"
android:layout_height="100dp">
</ImageView>
<TextView
android:layout_width="wrap_content"
android:id="@+id/textview"
android:text="SOmetext "
android:layout_height="wrap_content"
android:textColor="@color/colorPrimaryDark"
android:layout_gravity="center" /></FrameLayout>