android studio文本框样式
时间: 2023-04-15 18:02:24 浏览: 145
在 Android Studio 中,你可以使用 layout 文件来设置文本框的样式。
例如,在布局文件中添加一个文本框:
```
<EditText
android:id="@+id/edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入文本"/>
```
你可以通过修改属性来改变文本框的样式,例如:
```
android:background="#000000" // 设置背景颜色
android:textColor="#ffffff" // 设置文本颜色
android:textSize="20sp" // 设置文本大小
```
也可以在代码中通过findViewById获取到这个EditText对象来设置文本框的样式。
```
EditText editText = findViewById(R.id.edit_text);
editText.setBackgroundColor(Color.BLACK);
editText.setTextColor(Color.WHITE);
editText.setTextSize(20);
```
还有一种方式是使用styles.xml文件来定义一个样式,然后在layout文件中使用这个样式。
```
<style name="MyEditTextStyle">
<item name="android:background">#000000</item>
<item name="android:textColor">#ffffff</item>
<item name="android:textSize">20sp</item>
</style>
<EditText
android:id="@+id/edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入文本"
style="@style/MyEditTextStyle" />
```
阅读全文
相关推荐


















