Android studio添加图片控件及按钮控件,进行相关参数修改。

Android studio新建一个项目,修改XML如下:
其中Activity名称为:MyControlImageView

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MyControlImageView">
    <!--线性布局嵌套-->
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <!--图片视图-->
        <ImageView
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:background="@drawable/switch1" />
        <!--图片视图-->
        <ImageView
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:src="@drawable/switch3" />

    </LinearLayout>
    <!--线性布局嵌套-->
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <!--直接改变Button背景色没有变化时,这时候可以将res/values/themes.xml下的       -->
        <!--<style name="Theme.HelloWorld" parent="Theme.MaterialComponents.DayNight.DarkActionBar">改为-->
        <!--<style name="Theme.HelloWorld" parent="Theme.MaterialComponents.DayNight.DarkActionBar.Bridge">-->
        <!--按钮控件-->
        <Button
            android:layout_width="80dp"
            android:layout_height="80dp"
            android:background="@drawable/switch1"
            android:text="按钮1" />
        <!--按钮控件文本调用res/values/string.xml,可以自己定义全局String-->
        <!--按钮控件-->
        <Button
            android:layout_width="80dp"
            android:layout_height="80dp"
            android:background="#acacac00"
            android:text="@string/btn2_text" />
    </LinearLayout>


</LinearLayout>

运行界面如下:
在这里插入图片描述

界面没有做排版,相对来说比较乱,不过没有影响相关参数的设定,主要是不想加入太多的其他排版代码。

注意此XML的button2的文本:android:text="@string/btn2_text"引用了res/values/string.xml里的值。

图片的背景图引用了 android:background=“@drawable/switch1”
在这里插入图片描述
图片是引用了该目录下的文件,图片是从外部文件复制后直接选择该文件夹drawable粘贴进去的,值得注意的值文件名称不能有中文存在。

在修改button按钮的背景色没有改变时,可以查看此参数是否为桥接状态。
直接改变Button背景色没有变化时,这时候可以将res/values/themes.xml下的

 <style name="Theme.MtlayoutActivity" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
  <--改为-->
 <style name="Theme.MtlayoutActivity" parent="Theme.MaterialComponents.DayNight.DarkActionBar.Bridge">

在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值