解決Android Studio Design界面不顯示layout控件的問題
Android Studio更新到3.1.3后,發(fā)現(xiàn)拖到Design中的控件在預(yù)覽界面中不顯示;
解決辦法:
在Styles.xml中的parent="..."中的Theme前添加Base
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Base.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>
</resources>
補(bǔ)充知識:AndroidStudio XML文件之style標(biāo)簽詳解
前言:
Android的樣式一般定義在res/values/styles.xml文件中,其中有一個(gè)根元素resource,樣式通過嵌套子標(biāo)簽style來完成,style可以嵌套多個(gè)item標(biāo)簽來設(shè)置不同的屬性,從而提高復(fù)用率。
什么是Style:
style是一個(gè)標(biāo)簽,該標(biāo)簽里可以嵌套多個(gè)item子標(biāo)簽,通過item標(biāo)簽的name設(shè)置不同的屬性,多個(gè)item組合起來就是一個(gè)style樣式
示例:
<style name="DefaultProgressDialog" parent="android:style/Theme.Dialog" >
<item name="android:windowFrame">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">@null</item>
</style>
Style標(biāo)簽里面的屬性:
name="XXX" 定義該style樣式的name名稱
parent="XXX" 可以繼承自哪一個(gè)Style標(biāo)簽,繼承以后可對父標(biāo)簽已經(jīng)有的屬性進(jìn)行重寫
Style標(biāo)簽里可以嵌套的標(biāo)簽:
item標(biāo)簽的屬性:
name="XXX" name里面的值可以為任意字符串,對應(yīng)的是某一個(gè)view的屬性值(如果要引用的view不存在這個(gè)屬性,默認(rèn)為這個(gè)屬性無效(忽略這個(gè)屬性),并不會報(bào)錯(cuò))
自定義控件里面的屬性值怎么在style的item標(biāo)簽里聲明:
在主工程的時(shí)候要加上包名:
<style name="navigationbar_radiogroup_style">
<item name="com.mobeta.android.dslv.view:drawableSize">@dimen/dp20</item>
</style>
在module或其他類庫的話,什么都不用加:
<style name="navigationbar_radiogroup_style">
<item name="drawableSize">@dimen/dp20</item>
</style>
常用item屬性:
窗口進(jìn)出動畫設(shè)置:
<style name="WheelSelect" parent="@android:style/Animation">
<item name="android:windowEnterAnimation">@anim/wheel_select_enter</item>
<item name="android:windowExitAnimation">@anim/wheel_select_exit</item>
</style>
設(shè)置Dialog的屬性:
<style name="DefaultProgressDialog" parent="android:style/Theme.Dialog">
<item name="android:windowFrame">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">@null</item>
</style>
各屬性顏色的位置

1.colorPrimary 應(yīng)用的主要色調(diào),actionBar默認(rèn)使用該顏色,Toolbar導(dǎo)航欄的底色
2.colorPrimaryDark 應(yīng)用的主要暗色調(diào),statusBarColor默認(rèn)使用該顏色
3.statusBarColor 狀態(tài)欄顏色,默認(rèn)使用colorPrimaryDark
4.windowBackground 窗口背景顏色
5.navigationBarColor 底部欄顏色
6.colorForeground 應(yīng)用的前景色,ListView的分割線,switch滑動區(qū)默認(rèn)使用該顏色
7.colorBackground 應(yīng)用的背景色,popMenu的背景默認(rèn)使用該顏色
8.colorAccent CheckBox,RadioButton,SwitchCompat等一般控件的選中效果默認(rèn)采用該顏色
9.colorControlNormal CheckBox,RadioButton,SwitchCompat等默認(rèn)狀態(tài)的顏色。
10.colorControlHighlight 控件按壓時(shí)的色調(diào)
11.colorControlActivated 控件選中時(shí)的顏色,默認(rèn)使用colorAccent
12.colorButtonNormal 默認(rèn)按鈕的背景顏色
13.editTextColor 默認(rèn)EditView輸入框字體的顏色。
14.textColor Button,textView的文字顏色
15.textColorPrimary DisableOnly RadioButton checkbox等控件的文字
16.textColorPrimary 應(yīng)用的主要文字顏色,actionBar的標(biāo)題文字默認(rèn)使用該顏色
17.colorSwitchThumbNormal: switch thumbs 默認(rèn)狀態(tài)的顏色. (switch off)
以上這篇解決Android Studio Design界面不顯示layout控件的問題就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Android中使用RecyclerView實(shí)現(xiàn)下拉刷新和上拉加載
RecyclerView 是Android L版本中新添加的一個(gè)用來取代ListView的SDK,它的靈活性與可替代性比listview更好。這篇文章主要介紹了Android中使用RecyclerView實(shí)現(xiàn)下拉刷新和上拉加載的相關(guān)資料,需要的朋友可以參考下2016-03-03
android studio使用SQLiteOpenHelper()建立數(shù)據(jù)庫的方法
這篇文章主要介紹了android studio使用SQLiteOpenHelper()建立數(shù)據(jù)庫的方法,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-03-03
Android Studio3.5開發(fā)工具(安卓開發(fā)工具)安裝步驟詳解
這篇文章主要為大家詳細(xì)介紹了Android Studio3.5開發(fā)工具安裝、安卓開發(fā)工具的安裝步驟,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-09-09

