导航:首页 > 操作系统 > androidstudio加按钮

androidstudio加按钮

发布时间:2023-07-23 23:52:17

A. 怎样在android中添加按钮并设置大小

1

打开你的android软件eclipse.exe

2

软件打开中

3

点击Finsh

4

新建一个工程。

5

建工程的参数如下。

6

打开新工程中的main.xml文件。

7

点击下面的main.xml,进入代码界面。

8

在初始代码的下面位置添加按钮代码。

9

代码如下。

B. 怎么在android studio中实现开关按钮

先在布局文件中添加一个Button,然后再在java代码中获取这个按钮,设置它的监听事件就可以了。
.xml:
<Button android:"@+id/button1"......>
.java:
Button btn = (Button) findViewById(R.id.button1);
btn .setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//你要执行的代码
}
});
这是一种方法

C. android studio中的button有哪些方法

先介绍下修改原理:首先打开位于android.widget包下面的Button.java文件,这里有一句关键的代码如下:
public
Button(Context
context,
AttributeSet
attrs)
{
this(context,
attrs,
com.android.internal.R.attr.buttonStyle);
}
1
2
3
其中com.android.internal.R.attr.buttonStyle就是我们修改样式的关键了,网上的教程的修改方法大都是:
<Button
style="@style/ButtonStyle"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_weight="1"
android:text="价格"
/>
1
2
3
4
5
6
也就是在对应的xml里面button控件里面编写style达到目的。
但是如果我们的app需要完全统一整个应用的button的样式,那么就需要在每一个button里面添加style。
这显然效率太低下了。
接下来打开我们项目中values文件夹下面的styles.xml文件,我们创建安卓项目的时候,会有一个默认的styles文件。
打开之后找到这段代码:
<style
name="AppBaseTheme"
parent="Theme.Holo.Light">
<!--
Theme
customizations
available
in
newer
API
levels
can
go
in
res/values-vXX/styles.xml,
while
customizations
related
to
backward-compatibility
can
go
here.
-->
</style>
<!--
Application
theme.
-->
<style
name="AppTheme"
parent="AppBaseTheme">
1
2
3
4
5
6
7
8
9
10
不保证读者的默认styles.xml和我的是一样的,不过大概是这个样子,有可能读者的最低支持是2.3、那么就没有Them.Light。
我们使用eclipse的快捷键打开这个Theme.Holo.Light。可以看到如下代码:
<style
name="Theme.Holo.Light"
parent="Theme.Light">
<item
name="colorForeground">@android:color/bright_foreground_holo_light</item>
<item
name="colorForegroundInverse">@android:color/bright_foreground_inverse_holo_light</item>
<item
name="colorBackground">@android:color/background_holo_light</item>
<item
name="colorBackgroundCacheHint">@android:drawable/background_cache_hint_selector_holo_light</item>
<item
name="disabledAlpha">0.5</item>
<item
name="backgroundDimAmount">0.6</item>

阅读全文

与androidstudio加按钮相关的资料

热点内容
企业服务器为什么不能被拷贝 浏览:119
用c编程实现txt搜索 浏览:854
JAVA小数随机数 浏览:336
app加拿大pc怎么操控的 浏览:698
光影app苹果怎么下载不了 浏览:971
php会员注册代码 浏览:511
csgo如何用128tick服务器 浏览:571
百度网度怎么解压 浏览:946
windowsopencv源码 浏览:945
origin平滑算法 浏览:875
unity程序员简历 浏览:63
单片机ifelse 浏览:695
如何理解php面向对象 浏览:96
macword转pdf 浏览:848
python列表求交集 浏览:874
解压包如何转音频 浏览:447
机明自动编程软件源码 浏览:326
php端口号设置 浏览:541
phperegreplace 浏览:320
androidgridview翻页 浏览:537