【问题标题】:Android 5 material design problemsAndroid 5 材料设计问题
【发布时间】:2015-07-05 23:38:39
【问题描述】:

我是 android 编程新手,我刚刚发现了什么是材料设计。

我有一些问题

  1. 如何制作类似于 google+ 或 google 应用程序的图标? (它们有色调,与其他的略有不同)
  2. 如何将材料设计添加到我的应用程序中? (状态栏和类似的东西......)
  3. 如何制作 FAB? 关于状态栏的颜色,我见过一些应用程序的标题栏更亮,状态栏更暗 我不希望我的应用程序是那样的 我该怎么办?
  4. 如何让我的应用程序在较低的 API 上运行? 哦,我正在使用 Eclipse 请不要给我链接到谷歌开发者,因为我们的国家是被禁止的

【问题讨论】:

  • 您应该尝试在万维网上搜索指南,而不是在这里询问。您一定会找到您提出的所有问题以及广泛的解释
  • 使用 VPN,连接到 Google Developers 网站并开始阅读。

标签: android material-design


【解决方案1】:

关于#1,

Right click on 'app' or the beginning of your project tree > New > Image Asset

您应该能够在其中自定义图标的大部分(如果不是全部)方面。

关于#2,

I don't understand exactly what you're asking. You can customize your Action Bar and stuff like that if you choose.

关于#3,

转到 res -> drawable 右键单击​​并创建一个新的可绘制资源并将其命名为 circle.xml。现在在新创建的文件中添加以下代码:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<item android:top="8px">
    <layer-list>
        <item>
            <shape android:shape="oval">
                <solid android:color="#08000000"/>
                <padding
                    android:bottom="3px"
                    android:left="3px"
                    android:right="3px"
                    android:top="3px"
                    />
            </shape>
        </item>
        <item>
            <shape android:shape="oval">
                <solid android:color="#09000000"/>
                <padding
                    android:bottom="2px"
                    android:left="2px"
                    android:right="2px"
                    android:top="2px"
                    />
            </shape>
        </item>
        <item>
            <shape android:shape="oval">
                <solid android:color="#10000000"/>
                <padding
                    android:bottom="2px"
                    android:left="2px"
                    android:right="2px"
                    android:top="2px"
                    />
            </shape>
        </item>
        <item>
            <shape android:shape="oval">
                <solid android:color="#11000000"/>
                <padding
                    android:bottom="1px"
                    android:left="1px"
                    android:right="1px"
                    android:top="1px"
                    />
            </shape>
        </item>
        <item>
            <shape android:shape="oval">
                <solid android:color="#12000000"/>
                <padding
                    android:bottom="1px"
                    android:left="1px"
                    android:right="1px"
                    android:top="1px"
                    />
            </shape>
        </item>
        <item>
            <shape android:shape="oval">
                <solid android:color="#13000000"/>
                <padding
                    android:bottom="1px"
                    android:left="1px"
                    android:right="1px"
                    android:top="1px"
                    />
            </shape>
        </item>
        <item>
            <shape android:shape="oval">
                <solid android:color="#14000000"/>
                <padding
                    android:bottom="1px"
                    android:left="1px"
                    android:right="1px"
                    android:top="1px"
                    />
            </shape>
        </item>
        <item>
            <shape android:shape="oval">
                <solid android:color="#15000000"/>
                <padding
                    android:bottom="1px"
                    android:left="1px"
                    android:right="1px"
                    android:top="1px"
                    />
            </shape>
        </item>

    </layer-list>
</item>

<item >

    <ripple xmlns:android="http://schemas.android.com/apk/res/android"
        android:color="?android:colorControlHighlight">
        <item android:id="@android:id/mask">
            <shape android:shape="oval">
                <solid android:color="#FFBB00" />
            </shape>
        </item>
        <item>
            <shape android:shape="oval">

                <solid android:color="@color/ColorPrimary" />


            </shape>
        </item>
    </ripple>

</item>

您必须注意,圆形包含在波纹标记中,此标记可确保圆形在触摸时对棒棒糖设备上的波纹效果做出反应。 现在转到 res -> layout 右键单击​​并选择创建一个新的布局资源,将其命名为 tool_bar.xml 并将以下代码添加到该文件:

<?xml version="1.0" encoding="utf-8"?>

<android.support.v7.widget.Toolbar
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:elevation="2dp"
android:theme="@style/Base.ThemeOverlay.AppCompat.Dark"
android:background="@color/ColorPrimary"
xmlns:android="http://schemas.android.com/apk/res/android" />

现在转到 res -> values 创建一个新的资源文件名为 colors.xml 并添加以下代码:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="ColorPrimary">#FF5722</color>
<color name="ColorPrimaryDark">#E64A19</color> // you can change the colors if you want, this is orange
</resources>

现在转到 activity_main.xml 并将以下代码添加到其中。还要确保将要在 FAB 中显示的图标添加到项目中。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<include
    android:id="@+id/toolbar"
    layout="@layout/tool_bar"

    ></include>

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentEnd="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:id="@+id/frameLayout">

    <TextView
        android:id="@+id/TextAct1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_centerVertical="true"
        android:layout_gravity="center"
        android:text="Edit this to say anything"
        android:textSize="25dp" />

    <ImageButton
        android:layout_margin="15dp"
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:src="@drawable/ic_action"
        android:background="@drawable/circle"
        android:id="@+id/imageButton"
        android:layout_gravity="right|bottom" />


</FrameLayout>
</RelativeLayout>

数字 3 的来源:http://www.android4devs.com/2015/03/how-to-make-floating-action-button-fab.html

关于#4,

使用 Eclipse,它可能无法正确更改 SDK 版本,只需右键单击和属性。打开清单文件并更改行:

<uses-sdk android:minSdkVersion="number-of-version-you-want" />

数字 4 的来源:Eclipse Android Change API Level

祝你好运,如果可以,请查看链接。

【讨论】:

  • 谢谢你所做的一切,但在最后一部分你说我怎么能改变我知道的 api 级别,但我说我怎么能在较低的 api 上使用材料设计
  • 在这种情况下,您的最低目标是哪个 API?
  • 我不知道!但我看到一些应用程序在 api 8 中运行,并且它们具有材料设计
【解决方案2】:

如果您无法查看开发者网站,则可以查看代码示例。您可以使用 SDK 管理器下载示例。

例如,在 Lollipop SDK 的示例文件夹 /ui/views 中,您可以找到 FloatingActionButton、CardView、Elevation、RevealEffect 和许多其他示例。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-06
    • 2014-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多