我已经实现了一个简单的搜索对话框,可以根据以下指南对我的应用程序中的数据进行自定义搜索(通过自定义提供程序):http://developer.android.com/guide/topics/search/search- dialog.html
问题是搜索栏的颜色和大小(超出操作栏的高度等)在我的应用程序的设计中不起作用.我知道如何在styles.xml文件中创建主题,但我不知道如何定位Android搜索对话框和建议listView.有谁知道我怎么做到这一点?
我正在使用ActionBarSherlock字幕并尝试使用样式更改字幕文本大小,但似乎不起作用.我不熟悉主题,所以......我怎么能改变它?
提前致谢
android android-layout android-theme actionbarsherlock android-actionbar
我想问一下如何在焦点上改变EditText边框.我想将原始的橙色渐变改为我自己的.
我想为Android小部件定义不同的可用样式.在下面的示例中,有两个ImageView小部件,其中一个使用我的"主题"样式,另一个使用manualy样式.我希望以我coluld省略'base_theme'前缀的方式实现配置文件,以便可以根据活动主题配置自动确定.
有关编写主题的文档提到了如何更改所有ImageView或按钮的样式,而不是具有样式属性的特定样式.我发现可以通过使用可设置样式的自定义组件来解决我的问题,但我认为有一些更好的方法来解决我的问题.
base_style.xml
<style name="base_theme" parent="android:Theme.NoTitleBar">
</style>
<style name="base_theme.event_list_filter">
<item name="android:orientation">horizontal</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_margin">10dp</item>
<item name="android:background">@drawable/base_white_rounded</item>
</style>
<style name="base_theme.base_event_list_filter_image">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:padding">10dp</item>
<item name="android:background">@drawable/vr_black_border</item>
</style>
<style name="base_theme.base_event_list_scrollable">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">0dp</item>
<item name="android:layout_weight">1</item>
<item name="android:background">@drawable/base_white_rounded</item>
</style>
<style name="base_theme.base_event_list_table">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">fill_parent</item>
</style>
Run Code Online (Sandbox Code Playgroud)
activity_layout.xml
<LinearLayout style="@style/base_theme.base_event_list_filter" >
<ImageView
style="@style/base_theme.base_event_list_filter_image"
android:src="@drawable/pic0" />
<ImageView
...
android:src="@drawable/pic1" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助,
Maciek
按照本教程http://cases.azoft.com/android-tutorial-floating-activity/后,我能够创建一个浮动活动.
但是,要这样做,我必须添加以下内容styles.xml:
<item name="android:windowIsTranslucent">true</item>
Run Code Online (Sandbox Code Playgroud)
是否可以仅使用Android/Java代码获得相同的效果?(例如在Activity.onAttachedToWindow()...中)
在此先感谢您的帮助.
[编辑01] styles.xml不能改变(我不应该知道它里面有什么......).但出于测试目的,我使用的是默认值:
<resources>
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
</style>
<style name="AppTheme" parent="AppBaseTheme">
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
[编辑02] Resources.Theme.applyStyle()似乎做我想要的(根据API描述:"将新属性值放入主题").所以我创建了以下内容custom_style.xml:
<resources>
<style name="MyCustomStyle" >
<item name="android:windowIsTranslucent">true</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
然后,onAttachedToWindow()我打电话给:
getTheme().applyStyle(R.style.MyCustomStyle, true);
Run Code Online (Sandbox Code Playgroud)
但它没有任何影响......
android android-layout android-theme android-windowmanager android-styles
我试图在Android中试用新的Material Theme.
我目前仍然坚持这个例外
03-06 09:35:50.177: D/AndroidRuntime(30607): Shutting down VM
03-06 09:35:50.178: E/AndroidRuntime(30607): FATAL EXCEPTION: main
03-06 09:35:50.178: E/AndroidRuntime(30607): Process: com.example.vivz, PID: 30607
03-06 09:35:50.178: E/AndroidRuntime(30607): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.vivz/com.example.vivz.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
03-06 09:35:50.178: E/AndroidRuntime(30607): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
03-06 09:35:50.178: E/AndroidRuntime(30607): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
03-06 09:35:50.178: E/AndroidRuntime(30607): at android.app.ActivityThread.access$800(ActivityThread.java:144)
03-06 09:35:50.178: E/AndroidRuntime(30607): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
03-06 09:35:50.178: E/AndroidRuntime(30607): at android.os.Handler.dispatchMessage(Handler.java:102)
03-06 09:35:50.178: E/AndroidRuntime(30607): at android.os.Looper.loop(Looper.java:135)
03-06 09:35:50.178: E/AndroidRuntime(30607): at android.app.ActivityThread.main(ActivityThread.java:5221)
03-06 …Run Code Online (Sandbox Code Playgroud) 我的应用程序的基本主题是:
<style name="AppTheme" parent="@android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">@style/MyActionBar</item>
<item name="android:actionBarTabTextStyle">@style/MyActionBarTabText</item>
<item name="android:actionBarTabBarStyle">@style/MyActionBarTabBar</item>
<item name="android:actionBarTabStyle">@style/MyActionBarTabView</item>
<item name="android:popupMenuStyle">@style/MyMenu</item>
<!--<item name="android:actionBarStyle">@style/window_action_bar_style</item>-->
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:windowContentOverlay">@null</item>
</style>
Run Code Online (Sandbox Code Playgroud)
我想将这个主题应用于一项活动.
<style name="AppTheme" parent="Theme.AppCompat.Light">
</style>
Run Code Online (Sandbox Code Playgroud)
但是,当我这样做时,我无法访问该活动中的SwitchCompat小部件:
<android.support.v7.widget.SwitchCompat/>
Run Code Online (Sandbox Code Playgroud)
我在这做错了什么?任何建议或解决方案将是最受欢迎的.当我尝试覆盖特定活动中的基本主题并尝试访问SwitchCompat小部件时,会发生此问题.我的项目已经非常大,我可以更改整个应用程序的基本主题,因为我将不得不对ActionBars和其他视图进行更改.怎么解决这个问题?
配置:
Android Studio 1.4 Preview 2
compileSdkVersion 23
buildToolsVersion '23'
minSdkVersion 15
targetSdkVersion 23
Up-to-date support libraries (v23)
Run Code Online (Sandbox Code Playgroud)
错误:[已更新]
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp.android.debug/com.myapp.mobile.activities.HomeActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.support.v7.app.k.onCreate(AppCompatDelegateImplBase.java:124)
at android.support.v7.app.AppCompatDelegateImplV7.onCreate(AppCompatDelegateImplV7.java:146)
at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:59) …Run Code Online (Sandbox Code Playgroud) 我试图通过应用主题修改EditText的下划线颜色.
样式:
<style name="MyTheme.EditText" parent="Widget.AppCompat.EditText">
<item name="colorControlActivated">@color/green</item>
</style>
Run Code Online (Sandbox Code Playgroud)
EditText上:
<EditText
android:id="@+id/editText_amount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/hint_enter_amount"
android:theme="@style/MyTheme.EditText"/>
Run Code Online (Sandbox Code Playgroud)
基本上它可以工作,但是当我尝试选择或移动光标时,选择手柄也有下划线.您可以在屏幕截图中看到这一点.
有人知道如何解决这个问题吗?
所以我研究了很多,有很多问题和答案谈论按钮和颜色.但在你投票之前看到这个问题更具体,更实际,我没有找到答案.
我正在使用元素Button作为我的xml布局.来自android.widget的Button类,它扩展了TextView.
此视图可以通过java代码标记为启用或禁用..setEnabled(true|false).
按钮xml代码
<Button
android:id="@+id/maps_list_save_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/str_save"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
Run Code Online (Sandbox Code Playgroud)
我想要的是什么:
我不想做的事:
创建一个新元素并包含布局,我正在避免这个,因为我想保留选定的动画,提升,填充,提升等.再创建一切并不聪明.
我已经尝试过:
更改背景 =它松开内部填充,什么使按钮更大,我想保持材料设计"规则"


更改主题 =我尝试通过编辑器和代码更改主题,但发生了两件事:或者我更改了不是按钮的更多内容,或者我更改了相同颜色的启用和禁用.
即使在寻找文档,我也没有找到如何正确使用这个元素.
android android-theme android-button android-view android-styles