当前位置: 首页 > news >正文

太原网络营销网站有哪些网站可以做推文

太原网络营销网站,有哪些网站可以做推文,梅州南站,pc网站自动转换wap网站目录 Android Button 按钮 基本的按钮 StateListDrawable 范例 使用颜色值绘制圆角按钮 自制水波纹效果 Android ImageButton 图片按钮 ImageButton 不同状态下的 ImageButton Android RadioButton 单选按钮 RadioButton 获得选中的值 Android Button 按钮 在 And…目录 Android Button 按钮 基本的按钮 StateListDrawable 范例 使用颜色值绘制圆角按钮 自制水波纹效果 Android ImageButton 图片按钮 ImageButton 不同状态下的 ImageButton Android RadioButton 单选按钮 RadioButton 获得选中的值 Android Button 按钮 在 Android 中Button 是用于创建一个按钮的组件它具有正常状态和点击状态并且继承自 TextView因此可以使用 TextView 的属性以及一些其他的属性。 基本的按钮 我们可以直接使用 XML 语法创建一个 Button ?xml version1.0 encodingutf-8? LinearLayoutxmlns:androidhttp://schemas.android.com/apk/res/androidandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:orientationhorizontalandroid:gravitycenterButtonandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text基本的按钮//LinearLayoutStateListDrawable StateListDrawable 是一种 Drawable 资源它可以根据控件的不同状态例如按下、获取焦点、可用等设置不同的图片或效果。关键在于 selector 元素它可以定义不同状态下的不同 Drawable。 以下是一些常用的 StateListDrawable 属性及其说明 drawable引用的 Drawable 位图放在最前面表示组件的正常状态。android:state_focused控件是否获得焦点。android:state_window_focused控件是否获得窗口焦点。android:state_enabled控件是否可用。android:state_checkable控件是否可勾选例如checkbox。android:state_checked控件是否被勾选。android:state_selected控件是否被选择针对有滚轮的情况。android:state_pressed控件是否被按下。android:state_active控件是否处于活动状态例如SlidingTab。android:state_single控件是否只显示一个子控件用于多个子控件的情况。android:state_first控件是否包含多个子控件时确定第一个子控件是否处于显示状态。android:state_middle控件是否包含多个子控件时确定中间一个子控件是否处于显示状态。android:state_last控件是否包含多个子控件时确定最后一个子控件是否处于显示状态。 通过定义 StateListDrawable可以根据控件的状态来设置不同的样式或效果从而提升用户交互体验。例如在按钮的背景中可以定义按下时的背景颜色从而在用户按下按钮时提供视觉反馈。 范例 ?xml version1.0 encodingutf-8? LinearLayoutxmlns:androidhttp://schemas.android.com/apk/res/androidandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:orientationhorizontalandroid:gravitycenter!-- 第一个按钮 --Buttonandroid:idid/myButtonandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text我的按钮 /!-- 第二个按钮 --Buttonandroid:idid/monitorButtonandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text监视器按钮android:backgroundcolor/black//LinearLayoutpackage com.example.myapplication;import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.drawable.BitmapDrawable; import android.os.Bundle; import android.view.MotionEvent; import android.view.View; import android.widget.Button; import android.widget.ImageView; import android.widget.LinearLayout;import androidx.appcompat.app.AppCompatActivity;public class MainActivity extends AppCompatActivity {Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);final Button myButton findViewById(R.id.myButton);final Button monitorButton findViewById(R.id.monitorButton);// 设置 monitorButton 的状态变化监听器myButton.setOnTouchListener(new View.OnTouchListener() {Overridepublic boolean onTouch(View v, MotionEvent event) {if (event.getAction() MotionEvent.ACTION_DOWN) {monitorButton.setText(监视器按钮111);} else if (event.getAction() MotionEvent.ACTION_UP) {monitorButton.setText(我的按钮已按下);}return true;}});// 设置 myButton 的禁用状态监听器monitorButton.setOnClickListener(new View.OnClickListener() {Overridepublic void onClick(View v) {if (myButton.isEnabled()) {myButton.setEnabled(false);monitorButton.setText(我的按钮已禁用);} else {myButton.setEnabled(true);monitorButton.setText(我的按钮已启用);}}});}}这样当按下 第一个按钮 时第二个按钮 的文本会变为 监视器按钮111松开按钮后文本会变为 我的按钮已按下。而当点击 第二个按钮 切换其禁用状态时第二个按钮 的文本会相应地变化为 我的按钮已禁用第一个按钮则处于禁用状态。 使用颜色值绘制圆角按钮 要使用颜色值绘制圆角按钮可以创建一个圆角矩形的 ShapeDrawable并将其设置为按钮的背景。 以下是一个示例 1、创建一个名为 rounded_button.xml 的 Drawable 资源文件定义一个圆角矩形形状 ?xml version1.0 encodingutf-8? shape xmlns:androidhttp://schemas.android.com/apk/res/androidandroid:shaperectanglecorners android:radius50dp/ !-- 设置圆角半径 --solid android:color#14EAD6/ !-- 设置背景颜色 -- /shape2、在布局文件中使用这个 Drawable 资源作为按钮的背景 ?xml version1.0 encodingutf-8? LinearLayoutxmlns:androidhttp://schemas.android.com/apk/res/androidandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:orientationhorizontalandroid:gravitycenterButtonandroid:idid/roundedButtonandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text圆形按钮android:backgrounddrawable/rounded_button//LinearLayout自制水波纹效果 1、创建一个名为 ripple_effect.xml 的 RippleDrawable 资源文件定义按钮的水波效果 ?xml version1.0 encodingutf-8? ripple xmlns:androidhttp://schemas.android.com/apk/res/androidandroid:color#F60F0F !-- 水波纹的颜色 --item android:idandroid:id/backgroundshape android:shaperectanglesolid android:color#9318DA/ !-- 背景颜色 --corners android:radius8dp/ !-- 圆角半径 --/shape/itemitem android:idandroid:id/maskshape android:shaperectanglesolid android:color#F60F0F/ !-- 背景颜色 --corners android:radius8dp/ !-- 圆角半径 --/shape/item /ripple2、在布局文件中使用 RippleDrawable 和 ShapeDrawable 组合作为按钮的背景 ?xml version1.0 encodingutf-8? LinearLayoutxmlns:androidhttp://schemas.android.com/apk/res/androidandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:orientationhorizontalandroid:gravitycenterButtonandroid:idid/customButtonandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:backgrounddrawable/ripple_effectandroid:text自定义波纹按钮 //LinearLayout这样就创建了一个具有背景颜色和水波效果的自定义按钮。当用户点击按钮时会显示出定义的水波纹效果并且按钮的背景颜色也会根据设置的颜色进行显示。 Android ImageButton 图片按钮 ImageButton 是 Android 中的一个 View与 Button 类似但是它显示的是一张图片而不是文字。 ImageButton 继承自 ImageView因此可以像 ImageView 一样使用 android:src 属性来设置图片资源。这使得可以在按钮中显示图像而不是文本从而增强用户界面的交互性和可视化效果。 ImageButton ImageButton 可以根据用户的交互动作显示不同的图像。默认情况下ImageButton 看起来像一个普通的按钮但可以根据需要设置不同的图像资源使其在不同的交互状态下显示不同的图像。 可以通过以下方式为 ImageButton 设置不同的图像资源 1、使用 android:src 属性在布局文件中为 ImageButton 设置默认图像资源。 ImageButtonandroid:idid/imageButtonandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:srcdrawable/background_image / 2、使用 setImageResource(int) 方法在代码中动态地设置 ImageButton 的图像资源。 ImageButtonandroid:idid/imageButtonandroid:layout_widthwrap_contentandroid:layout_heightwrap_content / ImageButton imageButton findViewById(R.id.imageButton); imageButton.setImageResource(R.drawable.background_image); 注意要移除 ImageButton 的背景图像可以使用 android:background 属性定义自定义的背景图像或者将背景颜色设置为透明。 以下是一个示例演示如何将 ImageButton 的背景颜色设置为透明 ?xml version1.0 encodingutf-8? LinearLayoutxmlns:androidhttp://schemas.android.com/apk/res/androidandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:orientationhorizontalandroid:gravitycenterImageButtonandroid:idid/imageButtonandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:srcdrawable/background_imageandroid:backgroundandroid:color/transparent //LinearLayout这样ImageButton 的背景颜色将会是透明的不会显示任何图像或颜色。 不同状态下的 ImageButton 要为 ImageButton 指示不同的按钮状态例如按下、选定等可以使用 StateListDrawable。StateListDrawable 是一种 Drawable 类型允许根据 View 的状态选择不同的 Drawable 来显示。 以下是一个示例演示如何为 ImageButton 定义不同状态下的图像 1、创建一个名为 button_states.xml 的 StateListDrawable 资源文件定义不同状态下的图像 ?xml version1.0 encodingutf-8? selector xmlns:androidhttp://schemas.android.com/apk/res/android!-- 聚焦时的图像 --item android:drawabledrawable/orange_image android:state_focusedtrue/!-- 按下时的图像 --item android:drawabledrawable/yellow_image android:state_pressedtrue/!-- 默认的图像 --item android:drawabledrawable/blue_image/ /selector注意 item 的顺序很重要一定要把 正常 的图片放在最后 因为它们是按照顺序来进行匹配的 2、在布局文件中使用这个 StateListDrawable 资源作为 ImageButton 的背景 ImageButtonandroid:idid/imageButtonandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:srcdrawable/button_states/Android RadioButton 单选按钮 RadioButton 是一种用于实现单选功能的按钮。 注意通常情况下得将多个 RadioButton 放置在一个 RadioGroup 中以确保只能选择一个 RadioButton。 RadioButton RadioButton 是一种特殊的按钮它继承自 Button并且只有两个状态选中和未选中。 因此它只有一个属性 android:checked 用于设置或获取 RadioButton 的选中状态。 以下是一个示例演示如何在布局文件中创建一个 RadioButton 并设置其选中状态 RadioButtonandroid:idid/radioButtonandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text特殊的按钮android:checkedtrue/ !-- 设置 RadioButton 初始为选中状态 --获得选中的值 要获取 RadioButton 的选中状态可以为 RadioButton 添加一个单击事件并在事件中调用 isChecked() 方法来判断 RadioButton 是否选中。 Android 快捷键生成onClick()点击事件方法将光标移到myOnclick上按快捷键AltEnter。 以下是一个示例演示如何在布局文件中为 RadioButton 添加单击事件并捕获其选中状态 ?xml version1.0 encodingutf-8? LinearLayoutxmlns:androidhttp://schemas.android.com/apk/res/androidandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:orientationhorizontalandroid:gravitycenterRadioGroupandroid:idid/radioGroupandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:orientationverticalRadioButtonandroid:idid/Javaandroid:text我要学习Javaandroid:onClickonRadioButtonClickedandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:checkedtrue/RadioButtonandroid:idid/Goandroid:text我要学习goandroid:onClickonRadioButtonClickedandroid:layout_widthwrap_contentandroid:layout_heightwrap_content /RadioButtonandroid:idid/Pythonandroid:text我要学习Pythonandroid:onClickonRadioButtonClickedandroid:layout_widthwrap_contentandroid:layout_heightwrap_content //RadioGroup /LinearLayoutpackage com.example.myapplication;import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.drawable.BitmapDrawable; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.RadioButton; import android.widget.TextView; import android.widget.Toast;import androidx.appcompat.app.AppCompatActivity;public class MainActivity extends AppCompatActivity {public void onRadioButtonClicked(View view) {// 判断是否在 RadioButton 上单击boolean checked ((RadioButton) view).isChecked();// 判断是哪个 RadioButton 被单击if (view.getId() R.id.Java || view.getId() R.id.Go || view.getId() R.id.Python) {if (checked)Toast.makeText(getApplicationContext(), 你选择了 ((RadioButton) view).getText(), Toast.LENGTH_LONG).show();}}Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);}}
http://www.w-s-a.com/news/271253/

相关文章:

  • 网站404报错热水器网站建设 中企动力
  • 网站降权恢复淘宝 网站建设
  • 安州区建设局网站台州优秀关键词优化
  • 网站假设教程湖南微信管理系统
  • 网站备案属于公司哪一块哪个网站是专门做封面素材
  • 广州个人做网站内江建设局网站
  • 网站开发 360百科大连哪里有手机自适应网站建设维护
  • 如何查网站pv网站功防教程
  • 建设银行网站信息补充营销推广的作用
  • 网站见建设seo外链自动群发工具
  • 在境外做网站网站团购网站seo
  • 进网站后台加什么360推广 网站建设
  • 网站备案号码专做网站漏扫的工具
  • 罗店网站建设wordpress响应式
  • 网站怎么制作小程序wordpress实时获取qq资料
  • 网站的流量怎么赚钱经销做网站都有什么好处
  • 如何做好网站首页企术建站
  • 杭州网站建设咨询蓝韵网络聊城有制作网站的吗
  • 网站开发注意的事项深圳企业网站
  • 哈尔滨网站制作哪里专业网站建设维护有哪些内容
  • 花的网站建设规划书网络营销培训
  • 又拍云wordpress全站cdn无锡做网站品牌公司
  • 计算机网络工程网站建设黄石建设信息网站
  • 旅游网站开发毕业设计开题报告青岛网站建设服务公司
  • 人员调动在网站上怎么做网站开发课程意见和建议
  • 卓训网是个什么网站wordpress命令执行时间
  • 网站建设需要做哪些工作网片焊接
  • 网站优化方案dedecms win8风格网站模板
  • 企业如何制作网站管理系统慈溪住房和城乡建设部网站
  • 青岛网站建设有哪些公司区块链网站开发价格