【问题标题】:Predefined styles and themes for Android适用于 Android 的预定义样式和主题
【发布时间】:2011-12-15 03:43:55
【问题描述】:

我已经完成了我的应用程序的逻辑编码,其中包含一个 GridView、一些 TextView 和一些对话框。

我现在希望设置这些视图的样式,因为默认主题有点难看。

我查看了提供的 Android 主题,并尝试了其中的一些,但它们并没有真正提供太多。 因此,我想知道是否有任何可用资源可以让我快速应用预定义的然后我可以相应地调整它? 能够在几个时尚主题之间切换以获取想法并对其进行调整将非常有益,因为我不是最注重图形的人。

谢谢

【问题讨论】:

  • 你想改变什么来让控件看起来不那么难看?如果足够的话,您可以在布局 XML 中编辑 textview 大小、字体和颜色。
  • 我想我可以做到这一点,但我希望可能有一些我可以用作基础的快速适应主题列表。默认的 Android 主题不是很好

标签: android android-theme android-styles


【解决方案1】:

这里我做了什么来改变我的对话框的样式。我首先定义了一个渐变填充背景和圆形边缘的形状:

filled_roundededges_box.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
    <gradient 
        android:startColor="#353535"
        android:endColor="#222222"
        android:angle="90" />
<stroke android:width="2dp" android:color="#808080"/>
<corners android:radius="5dp" />
<padding android:left="10dp" android:top="10dp"
    android:right="10dp" android:bottom="10dp" />
</shape>

然后我使用这个形状创建一个样式:

styles.xml:

<style name="AppCustomDialog" parent="android:style/Theme.Dialog">
    <item name="android:windowBackground">@drawable/filled_roundededges_box</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowSoftInputMode">stateVisible</item>
</style>

最后我将这个样式应用到我的按钮上:

<ImageButton
        android:id="@+id/addedit_btnPrev"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical|right"
        android:src="@drawable/left"
        style="@style/App_ButtonStyle" />

或者,您可以使用以下方式将样式作为主题应用到 who 应用:

<application
    android:icon="@drawable/ic_launcher_noteit1"
    android:label="@string/app_name" 
    android:theme="@style/App_Theme"
    android:name="NoteItApplication" 
    android:debuggable="true">

【讨论】:

  • 谢谢,我会试试这个。我认为 ImageButton 中的样式名称不正确?
  • 是的,对不起。但我希望你能明白要点。如果您想要更多灵活性,请查看我发现非常有趣的 androidengineer.com/2010/06/…。
猜你喜欢
  • 2017-05-11
  • 1970-01-01
  • 2014-06-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-01-29
  • 1970-01-01
相关资源
最近更新 更多