在Android模拟器中,按钮看起来很难看 [英] Buttons look ugly in Android emulator

查看:80
本文介绍了在Android模拟器中,按钮看起来很难看的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个主要布局.它应该显示3个按钮,但是我只向您显示1个按钮定义,以免在问题中放置大部分代码.其他按钮具有相同的定义.

I have this main layout. It should display 3 buttons, but I am showing you only 1 button definition in order not to put mostly code in the question.The other buttons have the same definition.

<?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:id="@+id/mainLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center"
    android:orientation="vertical"
    android:paddingTop="70dp"
    android:paddingBottom="70dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.5"
        android:gravity="center"
        android:orientation="horizontal"
        android:padding="50dp">

        <Button
            android:id="@+id/btnRfid"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/main_button_background"
            android:padding="20dp"
            android:text="@string/button_rfid"
            android:textSize="36sp"
            android:drawableLeft="@drawable/button_rfid"/>
    </LinearLayout>
</LinearLayout>

这是main_button_background.xml:

This is the main_button_background.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient android:startColor="#FFFFFF"
        android:endColor="#949597"
        android:angle="270" />
    <corners android:radius="20dp" />
    <stroke android:width="5px" android:color="#000000" />
</shape>

这就是我在Android Studio的设计编辑器中看到的样子:

This is how I see it in design editor of Android Studio:

但是,这是在模拟器中的显示方式:

However, this is how it is viewed in the emulator:

为什么用这种方式呈现文本?缺少什么了吗?

Why are text rendered that way? Is something missing?

通过阅读教程,我在按钮定义中看不到任何特别之处.

By reading tutorials, I don't see anything special in the button definition.

问候 海梅

推荐答案

1)将项目迁移到androidx.
2)在您的build.gradle中包含依赖项:

1) Migrate your project to androidx.
2) Include dependency in your build.gradle:

实现'com.google.android.material:material:1.0.0'

implementation 'com.google.android.material:material:1.0.0'

3)在您的布局中使用:

3) Use in your layout:

<com.google.android.material.button.MaterialButton
  android:id="@+id/material_icon_button"
  style="@style/Widget.MaterialComponents.Button.Icon"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:text="@string/icon_button_label_enabled"
  app:icon="@drawable/icon_24px"/>

4)不要忘记将您的应用程序级别主题更改为材料组件"主题.

4) Don't forget to change your applevel theme to Material Component theme.

<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>

</style>

这篇关于在Android模拟器中,按钮看起来很难看的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆