直播系統app原始碼,TabLayout:自定義字型大小
直播系統app原始碼,TabLayout:自定義字型大小實現的相關程式碼
1、主程式碼
//方式一: private String[] mTabs = new String[]{"案例", "宣傳"}; //方式二:動態生成資料 private String[] mTabs = {}; private List<String> firstList = new ArrayList<>(); firstList.add("案例"); firstList.add("宣傳"); mTabs = new String[firstList.size()]; firstList.toArray(mTabs); private void initTab() { addTab(tabLayout, position -> { }); } private void addTab(TabLayout tabLayout, OnTabChangedListener listener) { for (String tab : mTabs) { tabLayout.addTab(tabLayout.newTab().setText(tab)); } tabLayout.setScrollableTabRadius(5); tabLayout.setSelectedTabIndicatorWidth(70); tabLayout.setIndicatorVerticalOffset(0); tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {//改變選中狀態下文字大小 @Override public void onTabSelected(TabLayout.Tab tab) { setCustomTab(tab, true); if (listener != null) { listener.onTabChanged(tab.getPosition()); } } @Override public void onTabUnselected(TabLayout.Tab tab) { setCustomTab(tab, false); } @Override public void onTabReselected(TabLayout.Tab tab) { } }); TabLayout.Tab tab = tabLayout.getTabAt(0); if (tab != null) { setCustomTab(tab, true); } } private void setCustomTab(TabLayout.Tab tab, boolean isSelected) { tab.setCustomView(null); int color = Color.parseColor("#999999"); int size = 15; if (isSelected) { color = Color.parseColor("#333333"); size = 18; } @SuppressLint("InflateParams") TextView textView = (TextView) LayoutInflater.from(context).inflate(R.layout.item_tab_text, null); textView.setTextSize(size); textView.setTextColor(color); textView.setText(tab.getText()); tab.setCustomView(textView); }
2、自定義介面
public interface OnTabChangedListener { void onTabChanged(int position); }
3、xml
<com.x.common.widget.tablayout.TabLayout android:id="@+id/tl_title" android:layout_width="match_parent" android:layout_height="50dp" android:background="#ffffff" android:paddingTop="10dp" android:paddingBottom="6dp" app:tabGravity="center" app:tabIndicatorColor="@color/colorPrimary" app:tabIndicatorHeight="4dp" app:tabPaddingBottom="4dp" app:tabSelectedTextColor="@color/colorPrimary" /> <com.x.common.widget.MyTextView xmlns:android=" xmlns:app=" android:textSize="16sp" android:layout_gravity="center" android:gravity="center" android:textColor="@color/color_333" android:layout_width="wrap_content" app:tv_bottom_height="15dp" app:tv_bottom_width="20dp" android:layout_height="wrap_content"> </com.zswl.common.widget.MyTextView>
4、MyTextView
@SuppressLint("AppCompatCustomView") public class MyTextView extends AppCompatTextView { private float mLeftWidth; private float mLeftHeight; private float mTopWidth; private float mTopHeight; private float mRightWidth; private float mRightHeight; private float mBottomWidth; private float mBottomHeight; public MyTextView(Context context) { super(context); } public MyTextView(Context context, AttributeSet attrs) { super(context, attrs); TypedArray t = context.obtainStyledAttributes(attrs, R.styleable.MyTextView); mLeftWidth = t.getDimension(R.styleable.MyTextView_tv_left_width, dip2px(context, 15)); mLeftHeight = t.getDimension(R.styleable.MyTextView_tv_left_height, dip2px(context, 15)); mTopWidth = t.getDimension(R.styleable.MyTextView_tv_top_width, dip2px(context, 15)); mTopHeight = t.getDimension(R.styleable.MyTextView_tv_top_height, dip2px(context, 15)); mRightWidth = t.getDimension(R.styleable.MyTextView_tv_right_width, dip2px(context, 15)); mRightHeight = t.getDimension(R.styleable.MyTextView_tv_right_height, dip2px(context, 15)); mBottomWidth = t.getDimension(R.styleable.MyTextView_tv_bottom_width, dip2px(context, 15)); mBottomHeight = t.getDimension(R.styleable.MyTextView_tv_bottom_height, dip2px(context, 15)); t.recycle(); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { //讓RadioButton的圖示可調大小 屬性: Drawable drawableLeft = this.getCompoundDrawables()[0];//獲得文字左側圖片 Drawable drawableTop = this.getCompoundDrawables()[1];//獲得文字頂部圖片 Drawable drawableRight = this.getCompoundDrawables()[2];//獲得文字右側圖片 Drawable drawableBottom = this.getCompoundDrawables()[3];//獲得文字底部圖片 if (drawableLeft != null) { drawableLeft.setBounds(0, 0, (int) mLeftWidth, (int) mLeftHeight); } if (drawableTop != null) { drawableTop.setBounds(0, 0, (int) mTopWidth, (int) mTopHeight); } if (drawableRight != null) { drawableRight.setBounds(0, 0, (int) mRightWidth, (int) mRightHeight); } if (drawableBottom != null) { drawableBottom.setBounds(0, 0, (int) mBottomWidth, (int) mBottomHeight); } this.setCompoundDrawables(drawableLeft, drawableTop, drawableRight, drawableBottom); super.onMeasure(widthMeasureSpec, heightMeasureSpec); } public static int dip2px(Context context, float dpValue) { float scale = context.getResources().getDisplayMetrics().density; return (int) (dpValue * scale + 0.5f); } public void setDrawableRight(@DrawableRes int drawableRight) { Drawable drawableEnd = getResources().getDrawable(drawableRight); int size = dip2px(getContext(), 10); drawableEnd.setBounds(0, 0, size, size); setCompoundDrawables(null, null, drawableEnd, null); setCompoundDrawablePadding(size); } public void setDrawableRight(@DrawableRes int drawableRight, int size, int padding) { Drawable drawableEnd = getResources().getDrawable(drawableRight); size = dip2px(getContext(), size); drawableEnd.setBounds(0, 0, size, size); setCompoundDrawables(null, null, drawableEnd, null); setCompoundDrawablePadding(dip2px(getContext(), padding)); } public void setDrawableLeft(@DrawableRes int drawableRight, int size, int padding) { Drawable drawableStart = getResources().getDrawable(drawableRight); size = dip2px(getContext(), size); drawableStart.setBounds(0, 0, size, size); setCompoundDrawables(drawableStart, null, null, null); setCompoundDrawablePadding(dip2px(getContext(), padding)); } public void setDrawableTop(@DrawableRes int top, int size, int padding) { Drawable drawableTop = getResources().getDrawable(top); size = dip2px(getContext(), size); drawableTop.setBounds(0, 0, size, size); setCompoundDrawables(null, drawableTop, null, null); setCompoundDrawablePadding(dip2px(getContext(), padding)); } public void setDrawableTop(@DrawableRes int drawableTop) { Drawable drawabletop = getResources().getDrawable(drawableTop); int size = dip2px(getContext(), 10); drawabletop.setBounds(0, 0, size, size); setCompoundDrawables(null, drawabletop, null, null); setCompoundDrawablePadding(size); } public void setDrawableBottom(@DrawableRes int bottom, int size, int padding) { Drawable drawableBottom = getResources().getDrawable(bottom); size = dip2px(getContext(), size); drawableBottom.setBounds(0, 0, size, size); setCompoundDrawables(null, null, null, drawableBottom); setCompoundDrawablePadding(dip2px(getContext(), padding)); } public void setDrawableLeft(@DrawableRes int drawableLeft) { Drawable drawableStart = getResources().getDrawable(drawableLeft); int size = dip2px(getContext(), 15); drawableStart.setBounds(0, 0, size, size); setCompoundDrawables(drawableStart, null, null, null); setCompoundDrawablePadding(dip2px(getContext(), 5)); } public void setDrawableNone() { setCompoundDrawables(null, null, null, null); } }
5、自定義屬性
<declare-styleable name="MyTextView"> <attr name="tv_left_width" format="dimension" /> <attr name="tv_left_height" format="dimension" /> <attr name="tv_top_width" format="dimension" /> <attr name="tv_top_height" format="dimension" /> <attr name="tv_right_width" format="dimension" /> <attr name="tv_right_height" format="dimension" /> <attr name="tv_bottom_width" format="dimension" /> <attr name="tv_bottom_height" format="dimension" /> </declare-styleable>
以上就是 直播系統app原始碼,TabLayout:自定義字型大小實現的相關程式碼,更多內容歡迎關注之後的文章
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69978258/viewspace-2845648/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- app直播原始碼,java自定義註解APP原始碼Java
- 直播系統app原始碼,自定義可以暫停的倒數計時APP原始碼
- 直播系統原始碼,修改ToolBar的標題的字型顏色大小原始碼
- 直播app系統原始碼,在 Flutter 中更改文字的字型系列APP原始碼Flutter
- 影片直播系統原始碼,自定義背景和狀態管理原始碼
- 線上直播系統原始碼,自定義底部 BottomNavigationBar原始碼Navigation
- app直播原始碼,uniapp之自定義頂部樣式APP原始碼
- Android中TabLayout修改字型大小AndroidTabLayout
- app直播原始碼,vue 自定義指令過濾特殊字元APP原始碼Vue字元
- 直播系統app原始碼,自定義中間向兩邊滑動的滑動條APP原始碼
- 直播帶貨系統原始碼利用TextView設定部分字型的顏色和大小原始碼TextView
- 直播系統app原始碼,自定義九宮格,計算器佈局,驗證碼認證APP原始碼
- app直播原始碼,el-button自定義圖片顯示APP原始碼
- 自定義Toast的背景顏色大小及字型大小AST
- 教育直播APP原始碼開發系統APP原始碼
- 直播系統原始碼,簡易的自定義確認彈框AlertDialog原始碼
- app直播原始碼,TextView部分字型顏色高亮APP原始碼TextView
- 影片直播app原始碼,自定義View 線型EditText輸入框APP原始碼View
- app直播原始碼,自定義兩種Activity切換動畫實現APP原始碼動畫
- Android 自定義 TabLayoutAndroidTabLayout
- 直播APP原始碼,直播系統推流SDK(Android)APP原始碼Android
- 直播商城系統原始碼,播放器aliPlayer自定義清晰度切換原始碼播放器
- 直播系統app原始碼,元素水平垂直居中APP原始碼
- 找靠譜商家直播系統原始碼app!原始碼APP
- 線上直播原始碼,自定義氣泡效果(BubbleView)原始碼View
- app直播系統原始碼,點選生成條形碼APP原始碼
- iOS 在 App 中使用自定義字型iOSAPP自定義字型
- 教育直播APP系統原始碼,原生開發功能APP原始碼
- app直播原始碼,Android 設定系統亮度APP原始碼Android
- 影片直播系統原始碼,在Laravel中自定義模板函式 並在模板中呼叫原始碼Laravel函式
- 視訊直播系統原始碼,使用自定義UI 完成文字顏色載入效果原始碼UI
- 直播系統app原始碼,設定樣式(字型樣式、行列寬高、對齊方式、邊框)APP原始碼
- 直播系統程式碼,自定義平臺私聊對話方塊
- 直播APP原始碼系統家族功能開發介紹APP原始碼
- 直播系統app原始碼,滑塊效果、slider用法APP原始碼IDE
- 社交直播APP 社交直播原始碼 1對1與1對多直播系統APP原始碼
- Vue富文字帶圖片修改圖片大小自定義選擇項自定義字型Vue自定義字型
- 手機直播原始碼,Flutter 自定義 虛線 分割線原始碼Flutter