目前,我正尝试将Tab
中的一个TabLayout
与其他Tab
区别开来。我希望一个具有特定索引的Tab
具有红色文本,包括选中和未选中。因为我只要求在特定索引处只有一个app:tabSelectedTextColor="@color/red"
app:tabTextColor="@color/red"
,所以下面的常用解决方案不起作用:
Spannable
我还尝试在返回特定Tab
的标题时应用@Override
public CharSequence getPageTitle(int position) {
switch (position) {
case TAB_ONE:
return getString(R.string.tab_one);
case TAB_TWO_RED:
Spannable spannable = new SpannableString(getString(R.string.tab_two));
spannable.setSpan(new ForegroundColorSpan(Color.RED),
0, getString(R.string.tab_two).length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
return spannable;
}
return null;
}
,但这实际上并未显示:
Tab
如果有人知道如何为仅具有指定索引的public class BloggingContext : DbContext
{
public DbSet<Blog> Blogs { get; set; }
public DbSet<Post> Posts { get; set; }
public DbSet<User> Users { get; set; }
public DbSet<Group> Groups { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlite("Filename=./Blogging.db");
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<UserGroup>().HasKey(x => new { x.UserId, x.GroupId });
modelBuilder.Entity<UserGroup>()
.HasOne(pc => pc.User)
.WithMany(p => p.UserGroups)
.HasForeignKey(pc => pc.UserId);
modelBuilder.Entity<UserGroup>()
.HasOne(pc => pc.Group)
.WithMany(c => c.UserGroups)
.HasForeignKey(pc => pc.GroupId);
}
}
public class Blog
{
public int BlogId { get; set; }
public string Url { get; set; }
public List<Post> Posts { get; set; }
}
public class Post
{
public int PostId { get; set; }
public string Title { get; set; }
public string Content { get; set; }
public int MadeBy { get; set; }
public int BlogId { get; set; }
public Blog Blog { get; set; }
}
public class User
{
[Key]
public int Id { get; set; }
public ICollection<UserGroup> UserGroups { get; set; }
}
public class Group
{
[Key]
public int Id { get; set; }
public ICollection<UserGroup> UserGroups { get; set; }
}
// Needed for many-to-many https://stackoverflow.com/questions/29442493/how-to-create-a-many-to-many-relationship-with-latest-nightly-builds-of-ef-core
public class UserGroup
{
[ForeignKey("User")]
public int UserId { get; set; }
public User User { get; set; }
[ForeignKey("Group")]
public int GroupId { get; set; }
public Group Group { get; set; }
}
设置文本样式,我将非常感激。
答案 0 :(得分:2)
这很简单。
尝试将customView
设置为TabLayout
中的特定标签,如下所示:
TabLayout tabLayout;
tabLayout = (TabLayout) findViewById(R.id.pTabs);
tabLayout.getTabAt(1).setCustomView(R.layout.tab_two_layout);
您的自定义布局(R.layout.tab_two_layout
)的XML看起来与此类似:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:textStyle="bold"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:layout_width="60dp"
android:textColor="@color/red"
android:layout_gravity="center_vertical"
android:text="TEXT HERE"
android:layout_height="wrap_content"/>
</LinearLayout>