androidstudio运行后按下button文字消失

如题所述

第1个回答  2022-10-16
先介绍下修改原理:首先打开位于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头条萺垍 p=""> </button头条萺垍>

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萺垍头条 p=""> </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.莱垍头条

--> 莱垍头条

垍头条莱

<!-- 莱垍头条

Application莱垍头条

theme.莱垍头条

--> 条莱垍头

<style萺垍头条 p=""> </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条萺垍头 p=""> </style条萺垍头>

name="Theme.Holo.Light"莱垍头条

parent="Theme.Light">莱垍头条

<item头条萺垍 p=""> </item头条萺垍>

name="colorForeground">@android:color/bright_foreground_holo_light头条莱垍

<item萺垍头条 p=""> </item萺垍头条>

name="colorForegroundInverse">@android:color/bright_foreground_inverse_holo_light莱垍头条

<item头条萺垍 p=""> </item头条萺垍>

name="colorBackground">@android:color/background_holo_light垍头条莱

<item头条萺垍 p=""> </item头条萺垍>

name="colorBackgroundCacheHint">@android:drawable/background_cache_hint_selector_holo_light莱垍头条

<item条萺垍头 p=""> </item条萺垍头>

name="disabledAlpha">0.5莱垍头条

<item萺垍头条 p=""> </item萺垍头条>

name="backgroundDimAmount">0.6头条莱垍
相似回答