Guest User

Untitled

a guest
Apr 26th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.17 KB | None | 0 0
  1. <LinearLayout
  2. android:layout_width="match_parent"
  3. android:layout_height="match_parent"
  4. android:layout_weight="1"
  5. android:orientation="horizontal">
  6.  
  7. <RelativeLayout
  8. style="@style/AZ.Menu.Icon"
  9. android:layout_width="match_parent"
  10. android:layout_height="match_parent"
  11. android:background="@color/darkorange">
  12.  
  13. <ImageView
  14. android:id="@+id/menu_about"
  15. android:layout_width="match_parent"
  16. android:layout_height="match_parent"
  17. android:layout_centerInParent="true"
  18. android:src="@drawable/menu_about" />
  19.  
  20. <TextView
  21. style="@style/AZ.Menu.Label"
  22. android:layout_width="wrap_content"
  23. android:layout_height="wrap_content"
  24. android:text="@string/menu_about" />
  25. </RelativeLayout>
  26.  
  27. <RelativeLayout
  28. style="@style/AZ.Menu.Icon"
  29. android:layout_width="match_parent"
  30. android:layout_height="match_parent"
  31. android:background="@color/darkblue">
  32.  
  33. <ImageView
  34. android:id="@+id/menu_settings"
  35. android:layout_width="match_parent"
  36. android:layout_height="match_parent"
  37. android:layout_centerInParent="true"
  38. android:src="@drawable/menu_settings" />
  39.  
  40. <TextView
  41. style="@style/AZ.Menu.Label"
  42. android:layout_width="wrap_content"
  43. android:layout_height="wrap_content"
  44. android:text="@string/menu_settings" />
  45. </RelativeLayout>
  46.  
  47. <ImageView
  48. style="@style/AZ.Menu.Icon"
  49. android:layout_width="match_parent"
  50. android:layout_height="match_parent"
  51. android:background="@color/grey" />
  52.  
  53. </LinearLayout>
  54.  
  55. public class MenuItemView extends RelativeLayout {
  56.  
  57. private String mLabel;
  58. private int mLabelRes = 0;
  59. private int mBackgroundRes = 0;
  60. private int mIconRes = 0;
  61. private MenuItemViewBinding mBinding;
  62.  
  63. public MenuItemView(Context context, AttributeSet attrs) {
  64. super(context, attrs);
  65.  
  66. getAttributes(context, attrs);
  67. init(context);
  68. }
  69.  
  70. private void getAttributes(Context context, AttributeSet attrs) {
  71. TypedArray typedArray = context.getTheme().obtainStyledAttributes(
  72. attrs,
  73. R.styleable.MenuItemView,
  74. 0, 0);
  75.  
  76. try {
  77. mBackgroundRes = typedArray.getResourceId(R.styleable.MenuItemView_backgroundColor, R.color.grey);
  78. mLabel = typedArray.getString(R.styleable.MenuItemView_label);
  79. mLabelRes = typedArray.getResourceId(R.styleable.MenuItemView_label, 0);
  80. mIconRes = typedArray.getResourceId(R.styleable.MenuItemView_icon, 0);
  81. } finally {
  82. typedArray.recycle();
  83. }
  84. }
  85.  
  86. private void init(Context context) {
  87. mBinding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.menu_item_view, (ViewGroup) this.getParent(), true);
  88.  
  89. mBinding.conMenuItem.setBackgroundResource(mBackgroundRes);
  90. mBinding.txtMenuItem.setText(mLabelRes != 0 ? getContext().getString(mLabelRes) : mLabel);
  91. mBinding.imgMenuItem.setImageResource(mIconRes);
  92. invalidate();
  93. requestLayout();
  94. }}
  95.  
  96. <declare-styleable name="MenuItemView">
  97. <attr name="backgroundColor" format="reference|color" />
  98. <attr name="label" format="reference|string" />
  99. <attr name="icon" format="reference" />
  100. </declare-styleable>
  101.  
  102. <layout xmlns:android="http://schemas.android.com/apk/res/android">
  103.  
  104. <RelativeLayout
  105. style="@style/AZ.Menu.Icon"
  106. android:id="@+id/conMenuItem"
  107. android:layout_width="match_parent"
  108. android:layout_height="match_parent">
  109.  
  110. <ImageView
  111. android:id="@+id/imgMenuItem"
  112. android:layout_width="match_parent"
  113. android:layout_height="match_parent" />
  114.  
  115. <TextView
  116. android:id="@+id/txtMenuItem"
  117. style="@style/AZ.Menu.Label"
  118. android:layout_width="wrap_content"
  119. android:layout_height="wrap_content" />
  120.  
  121. <ProgressBar
  122. android:id="@+id/pgbMenuItem"
  123. android:layout_width="match_parent"
  124. android:layout_height="match_parent"
  125. android:layout_margin="5dp"
  126. android:indeterminateTint="@color/nightblue"
  127. android:indeterminateTintMode="src_atop"
  128. android:visibility="gone" />
  129.  
  130. </RelativeLayout>
  131.  
  132. <LinearLayout
  133. android:layout_width="match_parent"
  134. android:layout_height="match_parent"
  135. android:layout_weight="1"
  136. android:orientation="horizontal">
  137.  
  138. <com.azconception.taxi.view.MenuItemView
  139. style="@style/AZ.Menu.Icon"
  140. android:layout_width="match_parent"
  141. android:layout_height="match_parent"
  142. custom:background="@color/darkblue"
  143. custom:icon="@drawable/menu_item"
  144. custom:label="TEST" />
  145.  
  146. <com.azconception.taxi.view.MenuItemView
  147. style="@style/AZ.Menu.Icon"
  148. android:layout_width="match_parent"
  149. android:layout_height="match_parent"
  150. custom:background="@color/darkblue"
  151. custom:icon="@drawable/menu_item"
  152. custom:label="TEST" />
  153.  
  154. <com.azconception.taxi.view.MenuItemView
  155. style="@style/AZ.Menu.Icon"
  156. android:layout_width="match_parent"
  157. android:layout_height="match_parent"
  158. custom:background="@color/darkblue"
  159. custom:icon="@drawable/menu_item"
  160. custom:label="TEST" />
  161.  
  162. </LinearLayout>
Add Comment
Please, Sign In to add comment