8

在我的一项活动中,我的 EditText 视图曾经看起来像这样

在此处输入图像描述

但现在它们看起来像这样

在此处输入图像描述

我需要帮助把它改回来:从矩形到下划线。

背景

因为我需要创建一个自定义 ActionBar,所以我必须更改相关活动的主题YesterdayActivity,使用以下内容

风格:

<style name="CustomWindowTitleBackground">
        <item name="android:background">#323331</item>
    </style>

    <style name="CustomTheme" parent="android:Theme">
        <item name="android:windowTitleSize">40dip</item>
        <item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>
    </style>

显现:

  <activity
        android:name="com.example.YesterdayActivity"
        android:theme="@style/CustomTheme">
    </activity>

创建:

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        setContentView(R.layout.activity_yesterday);
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.yesterday_title_bar);
…
}
4

5 回答 5

0

从您的样式中删除此行

<item name="android:background">#323331</item>

因为它是反映行为的背景属性。

于 2015-04-16T13:09:21.770 回答
0

像这样更改您的自定义主题

<style name="CustomTheme" parent="android:Theme.Holo.NoActionBar">

因为你没有使用旧的 android 主题而不是HoLo那种editTextView

在较新版本的 Android 中,Window.FEATURE_ACTION_BAR只要选择 Holo 主题,框架就会使用该功能。每当应用程序调用setFeatureInt(Window.FEATURE_CUSTOM_TITLE)FEATURE_ACTION_BAR已设置时,框架都会引发异常。它崩溃是因为 Holo 默认使用 ActionBar。修复很简单。使用 Holo 时关闭 ActionBar

于 2013-07-12T06:34:16.777 回答
0
<item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>

将其更改回您的默认样式。或者从代码中删除这一行。

导致您共享的第一张图片是默认的 Editext 背景。

于 2018-08-08T08:06:54.643 回答
0

如果您更改editText的主题,它可以实现。

<EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="textPersonName"
        android:text="Name"
        android:theme="@android:style/Theme.Holo"
        android:ems="10"
        android:id="@+id/editText"
        android:layout_below="@+id/textView"
        android:layout_centerHorizontal="true" />
于 2016-09-27T14:24:00.707 回答
0

有两种方法可以实现这一点。通过更改应用程序主题的第一种方法

第一种方法:

AndroidManifest.xml

见安卓:主题

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    ...
    ...
    </application>

res/values/style.xml

Theme.AppCompat.Light.DarkActionBar使 EditText 加下划线

<style name="AppTheme" parent="Theme.AppCompat.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>

只需以相同的方式使用 EditText

<EditText
      android:layout_width="match_parent"
      android:layout_height="48dp"
      android:hint="Email Address"
      android:inputType="textMultiLine"
      android:textSize="16dp" />

第二种方法:

创建一个带有底部笔划的可绘制形状并将其设置为 EditText 的背景

创建一个名为res/drawable/stroked_edittext_bg.xml的可绘制文件,如下链接所示:

如何使用底部描边创建 Android 形状

<EditText
      android:layout_width="match_parent"
      android:layout_height="48dp"
      android:background="@drawable/stroked_edittext_bg"
      android:hint="Email Address"
      android:inputType="textMultiLine"
      android:textSize="16dp" />
于 2016-07-28T08:10:58.407 回答