问题
In one of my activities, my EditText views used to look like this

But now they looks like this

I need help changing it back: from the rectangle to the underscore.
BACKGROUND
Because I needed to create a custom ActionBar, I had to change the theme of the activity in question, YesterdayActivity
, using the following
Style:
<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>
Manifest:
<activity
android:name="com.example.YesterdayActivity"
android:theme="@style/CustomTheme">
</activity>
onCreate:
@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);
…
}
回答1:
Change your custom theme like this
<style name="CustomTheme" parent="android:Theme.Holo.NoActionBar">
because you are not using old android theme not HoLo
which has that kinda editTextView
In newer versions of Android, the framework will use the Window.FEATURE_ACTION_BAR
feature whenever the Holo theme is selected. The framework throws the exception whenever an app calls setFeatureInt(Window.FEATURE_CUSTOM_TITLE)
and FEATURE_ACTION_BAR
has already been set.
it crashed because Holo uses the ActionBar by default. The fix was simple. Turn the ActionBar off when using Holo
回答2:
Remove this line from your style
<item name="android:background">#323331</item>
because it is the background attribute that reflects the behaviour.
回答3:
There are two ways to achieve this. First method by changing theme of your application
first method:
AndroidManifest.xml
See android:theme
<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 makes underlined 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>
Just use EditText in same way
<EditText
android:layout_width="match_parent"
android:layout_height="48dp"
android:hint="Email Address"
android:inputType="textMultiLine"
android:textSize="16dp" />
Second method:
Create a shape drawable with bottom stroke and set it as background of EditText
create a drawable file called res/drawable/stroked_edittext_bg.xml said in the below link:
How To Create An Android Shape With Bottom Stroke
<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" />
回答4:
it can be achieve, if you change the theme for 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" />
回答5:
<item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>
Change back it to your default style. Or remove this line from code.
Cause the 1st image you shared that is a default Editext background.
来源:https://stackoverflow.com/questions/17607173/change-android-edittext-style-from-rectangular-border-to-underscore