#
whycq
2024-08-20 e7ebc96482393d6b5b7ea4583f0bdb358e4afeeb
#
3个文件已添加
1个文件已修改
212 ■■■■■ 已修改文件
app/src/main/java/com/example/customBtn/CustomBtn.java 38 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/res/layout/activity_main.xml 158 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/res/values/customColors.xml 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/res/values/styles.xml 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/com/example/customBtn/CustomBtn.java
New file
@@ -0,0 +1,38 @@
package com.example.customBtn;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import com.example.agvcontroller.R;
import com.google.android.material.button.MaterialButton;
public class CustomBtn extends MaterialButton {
    public CustomBtn(@NonNull Context context) {
        super(context);
        init(context, null);
    }
    public CustomBtn(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }
    public CustomBtn(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }
    private void init(Context context, @Nullable AttributeSet attrs) {
        setBackgroundTintList(null);
        ColorStateList colorStateList = ContextCompat.getColorStateList(context, R.color.bulue_100);
        if (colorStateList != null) {
            setBackgroundTintList(colorStateList);
        }
        //setBackgroundColor(getResources().getColor(R.color.bulue_100,null));
    }
}
app/src/main/res/layout/activity_main.xml
@@ -94,7 +94,7 @@
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="6"
        android:visibility="visible">
        android:visibility="gone">
        <Button
            android:id="@+id/btn_stop2"
@@ -112,7 +112,7 @@
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="10sp"
            android:backgroundTint="#2196F3"
            android:backgroundTint="@color/bulue.500"
            android:minWidth="10dp"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
@@ -468,6 +468,160 @@
    </RelativeLayout>
    <!--    ****************  18轴  ****************    -->
    <GridLayout
        android:id="@+id/layout_18"
        android:visibility="visible"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="6"
        android:columnCount="4"
        android:rowCount="2"
        android:padding="5dp">
        <com.example.customBtn.CustomBtn
            android:id="@+id/btn_axle_1_front"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_columnWeight="1"
            style="@style/CustomButtonStyle"
            android:text="前进"/>
        <com.example.customBtn.CustomBtn
            android:id="@+id/btn_axle_1_back"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_columnWeight="1"
            style="@style/CustomButtonStyle"
            android:text="后退"/>
        <com.example.customBtn.CustomBtn
            android:id="@+id/btn_axle_2_front"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_columnWeight="1"
            style="@style/CustomButtonStyle"
            android:text="左旋转"/>
        <com.example.customBtn.CustomBtn
            android:id="@+id/btn_axle_2_back"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_columnWeight="1"
            style="@style/CustomButtonStyle"
            android:text="右旋转"/>
        <com.example.customBtn.CustomBtn
            android:id="@+id/btn_axle_3_front"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_columnWeight="1"
            style="@style/CustomButtonStyle"
            android:text="左旋转"/>
        <com.example.customBtn.CustomBtn
            android:id="@+id/btn_axle_3_back"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_columnWeight="1"
            style="@style/CustomButtonStyle"
            android:text="右旋转"/>
        <com.example.customBtn.CustomBtn
            android:id="@+id/btn_axle_4_front"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_columnWeight="1"
            style="@style/CustomButtonStyle"
            android:text="左旋转"/>
        <com.example.customBtn.CustomBtn
            android:id="@+id/btn_axle_4_back"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_columnWeight="1"
            style="@style/CustomButtonStyle"
            android:text="右旋转"/>
        <com.example.customBtn.CustomBtn
            android:id="@+id/btn_axle_5_front"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_columnWeight="1"
            style="@style/CustomButtonStyle"
            android:text="左旋转"/>
        <com.example.customBtn.CustomBtn
            android:id="@+id/btn_axle_5_back"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_columnWeight="1"
            style="@style/CustomButtonStyle"
            android:text="右旋转"/>
        <com.example.customBtn.CustomBtn
            android:id="@+id/btn_axle_6_front"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_columnWeight="1"
            style="@style/CustomButtonStyle"
            android:text="左旋转"/>
        <com.example.customBtn.CustomBtn
            android:id="@+id/btn_axle_6_back"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_columnWeight="1"
            style="@style/CustomButtonStyle"
            android:text="右旋转"/>
        <com.example.customBtn.CustomBtn
            android:id="@+id/btn_axle_7_front"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_columnWeight="1"
            style="@style/CustomButtonStyle"
            android:text="左旋转"/>
        <com.example.customBtn.CustomBtn
            android:id="@+id/btn_axle_7_back"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_columnWeight="1"
            style="@style/CustomButtonStyle"
            android:text="右旋转"/>
        <com.example.customBtn.CustomBtn
            android:id="@+id/btn_axle_8_front"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_columnWeight="1"
            style="@style/CustomButtonStyle"
            android:text="左旋转"/>
        <com.example.customBtn.CustomBtn
            android:id="@+id/btn_axle_8_back"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_columnWeight="1"
            style="@style/CustomButtonStyle"
            android:text="右旋转"/>
        <com.example.customBtn.CustomBtn
            android:id="@+id/btn_axle_9_front"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_columnWeight="1"
            style="@style/CustomButtonStyle"
            android:text="左旋转"/>
        <com.example.customBtn.CustomBtn
            android:id="@+id/btn_axle_9_back"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_columnWeight="1"
            style="@style/CustomButtonStyle"
            android:text="右旋转"/>
    </GridLayout>
    <!--    ****************  底部  ****************    -->
    <LinearLayout
        android:background="#334455"
app/src/main/res/values/customColors.xml
New file
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="bulue.100">#B2D7FF</color>
    <color name="bulue.200">#91C6FF</color>
    <color name="bulue.300">#91C6FF</color>
    <color name="bulue.500">#2196F3</color>
</resources>
app/src/main/res/values/styles.xml
New file
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="CustomButtonStyle" parent="Widget.MaterialComponents.Button">
        <item name="backgroundTint">@color/bulue.500</item>
        <item name="android:layout_margin">5dp</item>
        <item name="android:paddingLeft">5dp</item>
        <item name="android:paddingRight">5dp</item>
    </style>
</resources>