appcompat-v7:26 EditText 始终为白色
appcompat-v7:26 EditText always white
我是 android 编程新手,但描述我的问题的所有问题似乎都没有帮助。
Android edittext color white on white background
我正在查看的肯定是超级愚蠢的东西
我的Activity:
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="@string/font_family_regular"
android:hint="@string/user_name"
android:maxLines="1"
android:nextFocusDown="@+id/password"
android:imeOptions="actionNext"
android:inputType="text"
android:text=""
android:textColor="#000000"/>
</android.support.design.widget.TextInputLayout>
我的风格XML
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="android:textColor">@android:color/black</item>
<item name="android:textColorHint">@android:color/darker_gray</item>
<item name="colorAccent">#0000FF</item>
<item name="colorControlNormal">#0000FF</item>
<item name="colorControlActivated">#0000FF</item>
</style>
</resources>
Gradle 应用程序
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "com.myapp"
minSdkVersion 19
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2',
{
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support:design:26.+'
testCompile 'junit:junit:4.12'
}
如下更改appcomcat版本并检查
compile 'com.android.support:appcompat-v7:26.+'
您应该在 TextInputLayout 中添加 android:theme
而不是 EditText 部分 .
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme">
你应该设置
compile 'com.android.support:appcompat-v7:26.0.1'
compile 'com.android.support:design:26.0.1'
我想你应该试试这个:-
activity_main.xml
<android.support.design.widget.TextInputLayout
android:id="@+id/input_layout_name"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/ed_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Your Name"
android:textColor="@android:color/black"/>
</android.support.design.widget.TextInputLayout>
然后像这样更新你 style.xml:-
<!-- Base application theme. -->
<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>
我在这里找到了@Dahnark 发布的解决方案:
尝试在您的 EditText
中添加下一个代码
style="@style/Widget.AppCompat.EditText"
签入真机
在我的 EditText
作品中,这是我的 EditText:
<EditText
android:id="@+id/editTextFacebookID"
style="@style/Widget.AppCompat.EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="64dp"
android:layout_marginRight="8dp"
android:gravity="center_vertical"
android:hint="Facebook ID"
android:textColor="@color/md_text"
android:textColorHint="@color/md_disabled_hint_text" />
您可以在此处查看 md_text 和 md_disabled_hint_text 颜色:
Google Colors
这是我的应用程序的 v19 风格:
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/md_red_500</item>
<item name="colorPrimaryDark">@color/md_red_700</item>
<item name="colorAccent">@color/md_blue_A200</item>
<item name="colorControlHighlight">@color/md_black_1000_25</item>
<item name="colorControlNormal">@color/md_black_1000_50</item>
<item name="colorSwitchThumbNormal">@color/md_grey_200</item>
<item name="android:colorForeground">@color/md_black_1000_75</item>
<item name="android:windowTranslucentNavigation">@bool/translucentNavigationBar</item>
<item name="android:windowTranslucentStatus">@bool/translucentStatusBar</item>
<!-- Navigation Drawer Arrow Style. -->
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
<!-- Overflow Button Style. -->
<item name="actionOverflowButtonStyle">@style/OverflowStyle</item>
</style>
我的EditText在没有聚焦的时候是灰色的,聚焦的时候是蓝色的,它需要
来自 colorAccent 的颜色。
当我更改 AppTheme 时它会改变颜色。
我是 android 编程新手,但描述我的问题的所有问题似乎都没有帮助。
Android edittext color white on white background
我正在查看的肯定是超级愚蠢的东西
我的Activity:
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="@string/font_family_regular"
android:hint="@string/user_name"
android:maxLines="1"
android:nextFocusDown="@+id/password"
android:imeOptions="actionNext"
android:inputType="text"
android:text=""
android:textColor="#000000"/>
</android.support.design.widget.TextInputLayout>
我的风格XML
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="android:textColor">@android:color/black</item>
<item name="android:textColorHint">@android:color/darker_gray</item>
<item name="colorAccent">#0000FF</item>
<item name="colorControlNormal">#0000FF</item>
<item name="colorControlActivated">#0000FF</item>
</style>
</resources>
Gradle 应用程序
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "com.myapp"
minSdkVersion 19
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2',
{
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support:design:26.+'
testCompile 'junit:junit:4.12'
}
如下更改appcomcat版本并检查
compile 'com.android.support:appcompat-v7:26.+'
您应该在 TextInputLayout 中添加 android:theme
而不是 EditText 部分 .
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme">
你应该设置
compile 'com.android.support:appcompat-v7:26.0.1'
compile 'com.android.support:design:26.0.1'
我想你应该试试这个:-
activity_main.xml
<android.support.design.widget.TextInputLayout
android:id="@+id/input_layout_name"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/ed_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Your Name"
android:textColor="@android:color/black"/>
</android.support.design.widget.TextInputLayout>
然后像这样更新你 style.xml:-
<!-- Base application theme. -->
<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>
我在这里找到了@Dahnark 发布的解决方案:
尝试在您的 EditText
style="@style/Widget.AppCompat.EditText"
签入真机
在我的 EditText
作品中,这是我的 EditText:
<EditText
android:id="@+id/editTextFacebookID"
style="@style/Widget.AppCompat.EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="64dp"
android:layout_marginRight="8dp"
android:gravity="center_vertical"
android:hint="Facebook ID"
android:textColor="@color/md_text"
android:textColorHint="@color/md_disabled_hint_text" />
您可以在此处查看 md_text 和 md_disabled_hint_text 颜色: Google Colors
这是我的应用程序的 v19 风格:
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/md_red_500</item>
<item name="colorPrimaryDark">@color/md_red_700</item>
<item name="colorAccent">@color/md_blue_A200</item>
<item name="colorControlHighlight">@color/md_black_1000_25</item>
<item name="colorControlNormal">@color/md_black_1000_50</item>
<item name="colorSwitchThumbNormal">@color/md_grey_200</item>
<item name="android:colorForeground">@color/md_black_1000_75</item>
<item name="android:windowTranslucentNavigation">@bool/translucentNavigationBar</item>
<item name="android:windowTranslucentStatus">@bool/translucentStatusBar</item>
<!-- Navigation Drawer Arrow Style. -->
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
<!-- Overflow Button Style. -->
<item name="actionOverflowButtonStyle">@style/OverflowStyle</item>
</style>
我的EditText在没有聚焦的时候是灰色的,聚焦的时候是蓝色的,它需要 来自 colorAccent 的颜色。
当我更改 AppTheme 时它会改变颜色。