我正在做一个android项目,它应该支持2.2(froyo)及更高版本的所有android设备。我正在尝试在我的项目中使用 Android 材料设计。为了支持旧版本中的材料设计,我在 gradle 中添加了以下给出的语句
dependencies {
compile "com.android.support:appcompat-v7:21.0.+"
}
但它在旧版本中无法正常工作。任何人都可以提出任何解决方案来解决这个问题。如何让旧版本设备支持 Android Material Design? 谢谢你
旧版本支持Android Material Design,您应该使用支持库的类。
示例:
class Myclass extends Activity{
getActionBar();
}
//Change by
class Myclass extends ActionBarActivity{
getSupportActionBar();
}
您可以创建一个 xml 文件,例如。 color.xml 并放入您的项目 /res/values/ 目录中,您只需创建一个新的 .xml 文件即可。
这个colors.xml 文件应该是这样的:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="red_50">#fde0dc</color>
<color name="red_100">#f9bdbb</color>
<color name="red_200">#f69988</color>
<color name="red_300">#f36c60</color>
<color name="red_400">#e84e40</color>
<color name="red_500">#e51c23</color>
<color name="red_600">#dd191d</color>
<color name="red_700">#d01716</color>
<color name="red_800">#c41411</color>
<color name="red_900">#b0120a</color>
<color name="red_A100">#ff7997</color>
<color name="red_A200">#ff5177</color>
<color name="red_A400">#ff2d6f</color>
<color name="red_A700">#e00032</color>
<color name="pink_50">#fce4ec</color>
<color name="pink_100">#f8bbd0</color>
<color name="pink_200">#f48fb1</color>
<color name="pink_300">#f06292</color>
<color name="pink_400">#ec407a</color>
<color name="pink_500">#e91e63</color>
<color name="pink_600">#d81b60</color>
<color name="pink_700">#c2185b</color>
<color name="pink_800">#ad1457</color>
<color name="pink_900">#880e4f</color>
<color name="pink_A100">#ff80ab</color>
<color name="pink_A200">#ff4081</color>
<color name="pink_A400">#f50057</color>
<color name="pink_A700">#c51162</color>
<color name="purple_50">#f3e5f5</color>
<color name="purple_100">#e1bee7</color>
<color name="purple_200">#ce93d8</color>
<color name="purple_300">#ba68c8</color>
<color name="purple_400">#ab47bc</color>
<color name="purple_500">#9c27b0</color>
<color name="purple_600">#8e24aa</color>
<color name="purple_700">#7b1fa2</color>
<color name="purple_800">#6a1b9a</color>
<color name="purple_900">#4a148c</color>
<color name="purple_A100">#ea80fc</color>
<color name="purple_A200">#e040fb</color>
<color name="purple_A400">#d500f9</color>
<color name="purple_A700">#aa00ff</color>
<color name="dark_purple_50">#ede7f6</color>
<color name="dark_purple_100">#d1c4e9</color>
<color name="dark_purple_200">#b39ddb</color>
<color name="dark_purple_300">#9575cd</color>
<color name="dark_purple_400">#7e57c2</color>
<color name="dark_purple_500">#673ab7</color>
<color name="dark_purple_600">#5e35b1</color>
<color name="dark_purple_700">#512da8</color>
<color name="dark_purple_800">#4527a0</color>
<color name="dark_purple_900">#311b92</color>
<color name="dark_purple_A100">#b388ff</color>
<color name="dark_purple_A200">#7c4dff</color>
<color name="dark_purple_A400">#651fff</color>
<color name="dark_purple_A700">#6200ea</color>
<color name="indigo_50">#e8eaf6</color>
<color name="indigo_100">#c5cae9</color>
<color name="indigo_200">#9fa8da</color>
<color name="indigo_300">#7986cb</color>
<color name="indigo_400">#5c6bc0</color>
<color name="indigo_500">#3f51b5</color>
<color name="indigo_600">#3949ab</color>
<color name="indigo_700">#303f9f</color>
<color name="indigo_800">#283593</color>
<color name="indigo_900">#1a237e</color>
<color name="indigo_A100">#8c9eff</color>
<color name="indigo_A200">#536dfe</color>
<color name="indigo_A400">#3d5afe</color>
<color name="indigo_A700">#304ffe</color>
<color name="blue_50">#e7e9fd</color>
<color name="blue_100">#d0d9ff</color>
<color name="blue_200">#afbfff</color>
<color name="blue_300">#91a7ff</color>
<color name="blue_400">#738ffe</color>
<color name="blue_500">#5677fc</color>
<color name="blue_600">#4e6cef</color>
<color name="blue_700">#455ede</color>
<color name="blue_800">#3b50ce</color>
<color name="blue_900">#2a36b1</color>
<color name="blue_A100">#a6baff</color>
<color name="blue_A200">#6889ff</color>
<color name="blue_A400">#4d73ff</color>
<color name="blue_A700">#4d69ff</color>
<color name="light_blue_50">#e1f5fe</color>
<color name="light_blue_100">#b3e5fc</color>
<color name="light_blue_200">#81d4fa</color>
<color name="light_blue_300">#4fc3f7</color>
<color name="light_blue_400">#29b6f6</color>
<color name="light_blue_500">#03a9f4</color>
<color name="light_blue_600">#039be5</color>
<color name="light_blue_700">#0288d1</color>
<color name="light_blue_800">#0277bd</color>
<color name="light_blue_900">#01579b</color>
<color name="light_blue_A100">#80d8ff</color>
<color name="light_blue_A200">#40c4ff</color>
<color name="light_blue_A400">#00b0ff</color>
<color name="light_blue_A700">#0091ea</color>
<color name="cyan_50">#e0f7fa</color>
<color name="cyan_100">#b2ebf2</color>
<color name="cyan_200">#80deea</color>
<color name="cyan_300">#4dd0e1</color>
<color name="cyan_400">#26c6da</color>
<color name="cyan_500">#00bcd4</color>
<color name="cyan_600">#00acc1</color>
<color name="cyan_700">#0097a7</color>
<color name="cyan_800">#00838f</color>
<color name="cyan_900">#006064</color>
<color name="cyan_A100">#84ffff</color>
<color name="cyan_A200">#18ffff</color>
<color name="cyan_A400">#00e5ff</color>
<color name="cyan_A700">#00b8d4</color>
<color name="teal_50">#e0f2f1</color>
<color name="teal_100">#b2dfdb</color>
<color name="teal_200">#80cbc4</color>
<color name="teal_300">#4db6ac</color>
<color name="teal_400">#26a69a</color>
<color name="teal_500">#9688</color>
<color name="teal_600">#00897b</color>
<color name="teal_700">#00796b</color>
<color name="teal_800">#00695c</color>
<color name="teal_900">#004d40</color>
<color name="teal_A100">#a7ffeb</color>
<color name="teal_A200">#64ffda</color>
<color name="teal_A400">#1de9b6</color>
<color name="teal_A700">#00bfa5</color>
<color name="green_50">#d0f8ce</color>
<color name="green_100">#a3e9a4</color>
<color name="green_200">#72d572</color>
<color name="green_300">#42bd41</color>
<color name="green_400">#2baf2b</color>
<color name="green_500">#259b24</color>
<color name="green_600">#0a8f08</color>
<color name="green_700">#0a7e07</color>
<color name="green_800">#056f00</color>
<color name="green_900">#0d5302</color>
<color name="green_A100">#a2f78d</color>
<color name="green_A200">#5af158</color>
<color name="green_A400">#14e715</color>
<color name="green_A700">#12c700</color>
<color name="light_green_50">#f1f8e9</color>
<color name="light_green_100">#dcedc8</color>
<color name="light_green_200">#c5e1a5</color>
<color name="light_green_300">#aed581</color>
<color name="light_green_400">#9ccc65</color>
<color name="light_green_500">#8bc34a</color>
<color name="light_green_600">#7cb342</color>
<color name="light_green_700">#689f38</color>
<color name="light_green_800">#558b2f</color>
<color name="light_green_900">#33691e</color>
<color name="light_green_A100">#ccff90</color>
<color name="light_green_A200">#b2ff59</color>
<color name="light_green_A400">#76ff03</color>
<color name="light_green_A700">#64dd17</color>
<color name="lime_50">#f9fbe7</color>
<color name="lime_100">#f0f4c3</color>
<color name="lime_200">#e6ee9c</color>
<color name="lime_300">#dce775</color>
<color name="lime_400">#d4e157</color>
<color name="lime_500">#cddc39</color>
<color name="lime_600">#c0ca33</color>
<color name="lime_700">#afb42b</color>
<color name="lime_800">#9e9d24</color>
<color name="lime_900">#827717</color>
<color name="lime_A100">#f4ff81</color>
<color name="lime_A200">#eeff41</color>
<color name="lime_A400">#c6ff00</color>
<color name="lime_A700">#aeea00</color>
<color name="yellow_50">#fffde7</color>
<color name="yellow_100">#fff9c4</color>
<color name="yellow_200">#fff59d</color>
<color name="yellow_300">#fff176</color>
<color name="yellow_400">#ffee58</color>
<color name="yellow_500">#ffeb3b</color>
<color name="yellow_600">#fdd835</color>
<color name="yellow_700">#fbc02d</color>
<color name="yellow_800">#f9a825</color>
<color name="yellow_900">#f57f17</color>
<color name="yellow_A100">#ffff8d</color>
<color name="yellow_A200">#ffff00</color>
<color name="yellow_A400">#ffea00</color>
<color name="yellow_A700">#ffd600</color>
<color name="amber_50">#fff8e1</color>
<color name="amber_100">#ffecb3</color>
<color name="amber_200">#ffe082</color>
<color name="amber_300">#ffd54f</color>
<color name="amber_400">#ffca28</color>
<color name="amber_500">#ffc107</color>
<color name="amber_600">#ffb300</color>
<color name="amber_700">#ffa000</color>
<color name="amber_800">#ff8f00</color>
<color name="amber_900">#ff6f00</color>
<color name="amber_A100">#ffe57f</color>
<color name="amber_A200">#ffd740</color>
<color name="amber_A400">#ffc400</color>
<color name="amber_A700">#ffab00</color>
<color name="orange_50">#fff3e0</color>
<color name="orange_100">#ffe0b2</color>
<color name="orange_200">#ffcc80</color>
<color name="orange_300">#ffb74d</color>
<color name="orange_400">#ffa726</color>
<color name="orange_500">#ff9800</color>
<color name="orange_600">#fb8c00</color>
<color name="orange_700">#f57c00</color>
<color name="orange_800">#ef6c00</color>
<color name="orange_900">#e65100</color>
<color name="orange_A100">#ffd180</color>
<color name="orange_A200">#ffab40</color>
<color name="orange_A400">#ff9100</color>
<color name="orange_A700">#ff6d00</color>
<color name="deep_orange_50">#fbe9e7</color>
<color name="deep_orange_100">#ffccbc</color>
<color name="deep_orange_200">#ffab91</color>
<color name="deep_orange_300">#ff8a65</color>
<color name="deep_orange_400">#ff7043</color>
<color name="deep_orange_500">#ff5722</color>
<color name="deep_orange_600">#f4511e</color>
<color name="deep_orange_700">#e64a19</color>
<color name="deep_orange_800">#d84315</color>
<color name="deep_orange_900">#bf360c</color>
<color name="deep_orange_A100">#ff9e80</color>
<color name="deep_orange_A200">#ff6e40</color>
<color name="deep_orange_A400">#ff3d00</color>
<color name="deep_orange_A700">#dd2c00</color>
<color name="brown_50">#efebe9</color>
<color name="brown_100">#d7ccc8</color>
<color name="brown_200">#bcaaa4</color>
<color name="brown_300">#a1887f</color>
<color name="brown_400">#8d6e63</color>
<color name="brown_500">#795548</color>
<color name="brown_600">#6d4c41</color>
<color name="brown_700">#5d4037</color>
<color name="brown_800">#4e342e</color>
<color name="brown_900">#3e2723</color>
<color name="grey_50">#fafafa</color>
<color name="grey_100">#f5f5f5</color>
<color name="grey_200">#eeeeee</color>
<color name="grey_300">#e0e0e0</color>
<color name="grey_400">#bdbdbd</color>
<color name="grey_500">#9e9e9e</color>
<color name="grey_600">#757575</color>
<color name="grey_700">#616161</color>
<color name="grey_800">#424242</color>
<color name="grey_900">#212121</color>
<color name="grey_black_1000">#000000</color>
<color name="grey_white_1000">#ffffff</color>
<color name="blue_grey_50">#eceff1</color>
<color name="blue_grey_100">#cfd8dc</color>
<color name="blue_grey_200">#b0bec5</color>
<color name="blue_grey_300">#90a4ae</color>
<color name="blue_grey_400">#78909c</color>
<color name="blue_grey_500">#607d8b</color>
<color name="blue_grey_600">#546e7a</color>
<color name="blue_grey_700">#455a64</color>
<color name="blue_grey_800">#37474f</color>
<color name="blue_grey_900">#263238</color>
<!-- Colors for the app -->
<color name="primary">@color/indigo_500</color>
<color name="primary_dark">@color/indigo_700</color>
<color name="accent">@color/pink_A200</color>
</resources>
通过这种方式,您可以使用以下方式访问布局的颜色:
@colors/“颜色名称”
您需要另外两个小文件来设置旧版本的材料
-以这种方式更改/res/values中的themes.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="AppTheme.Base"/>
<style name="AppTheme.Base" parent="Theme.AppCompat.Light">
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark</item>
<item name="android:textColorPrimary">@color/blue_grey_100</item>
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">true</item>
</style>
</resources>
-创建 v23/themes.xml,始终位于 /res/values 中:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="AppTheme.Base">
<item name="android:windowContentTransitions">true</item>
<item name="android:windowAllowEnterTransitionOverlap">true</item>
<item name="android:windowAllowReturnTransitionOverlap">true</item>
<item name="android:windowSharedElementEnterTransition">@android:transition/move</item>
<item name="android:windowSharedElementExitTransition">@android:transition/move</item>
</style>
</resources>
-更改 /res/values 中的 styles.xml:
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</resources>
请记住使用 appcompat-v7 和 support-v4 库编译您的项目。
Material UI 1.12 的某些功能不起作用,请考虑使用替代组件或实施临时解决方法,同时等待库维护人员提供更永久的修复。