我对Android开发很新.所以忍受我.
我一直在尝试将com.android.support:design:23.1.0中的图标和文本对齐一天.
显然,在com.android.support:design:23.1.0他们已经改变了默认的图标位置,顶部和文字在底部.
以前在com.android.support:design:23.0.1默认在同一行图标左边和文本图标
所以这里有一个简单的方法来解决它(虽然它可能有缺点,idk tbh):
change the version in your app's build.gradle. ex: 23.1.0 to 23.0.1 and build.
Run Code Online (Sandbox Code Playgroud)
还有一种更好的方法(这样你也可以在左,右,上,下对齐图标):
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAlignment="center"/>
Run Code Online (Sandbox Code Playgroud)
2.在你的活动java中
TextView newTab = (TextView) LayoutInflater.from(this).inflate(R.layout.custom_tab, null);
newTab.setText("tab1"); //tab label txt
newTab.setCompoundDrawablesWithIntrinsicBounds(your_drawable_icon_here, 0, 0, 0);
tabLayout.getTabAt(tab_index_here_).setCustomView(newTab);
Run Code Online (Sandbox Code Playgroud)
到目前为止,我已经实现了使图标显示在任何一侧,如下所示:
PS:setCompoundDrawablesWithIntrinsicBounds函数参数是4个侧面图标,如下所示:
setCompoundDrawablesWithIntrinsicBounds(leftDrawable, topDrawable, rightDrawable, bottomDrawable)
Run Code Online (Sandbox Code Playgroud) android android-support-library android-support-design android-tablayout
我似乎无法在我的TabLayout内部将我的标题标题左对齐.目前,标题是中心的.这就是我想要实现的目标.
这就是我现在所拥有的.我正在使用的代码如下:
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
app:tabGravity="fill"
app:tabMode="fixed"
app:tabTextColor="@color/white"
app:tabSelectedTextColor="@color/white"
app:tabIndicatorColor="@color/white"
android:background="@color/slate_grey"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.design.widget.TabLayout>
Run Code Online (Sandbox Code Playgroud) 我正在一个包含两个选项卡的屏幕上工作。我在这里使用 AppCompatActivity。我在选项卡中设置了带有文本的图标,但我希望图像右对齐,并且它们之间应该有一些空间。代码如下:
1. Activity_ProfessionalTimeline.java
public class Activity_ProfessionalTimeline extends AppCompatActivity implements OnClickListener {
private Toolbar toolbatTop;
private TabLayout tabLayout;
private ViewPager viewPager;
private TabsPagerAdapter mAdapter;
private ActionBar actionBar;
private int[] tabIcons = {
R.drawable.social,
R.drawable.professional
};
private ImageView _img_Profile;
private TextView _txt_UserName;
private TextView _txt_UserDestination;
ArrayList<Model_LoginDetails> arr_LogInUserDetails = new ArrayList<Model_LoginDetails>();
private ImageView _imt_userImage;
private ListView _listView_SelectOpition;
private boolean profilebtnstatus = false;
private RelativeLayout _relativelayour_status;
private ListView _listviewmoroption;
private DrawerLayout drawer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_professionalttimeline);
// Top Toolbar …Run Code Online (Sandbox Code Playgroud) android ×3