跨系統 theme 呼叫私有的 style v1

2021-09-11 21:14:42 字數 1296 閱讀 6942

乙個應用彈出框兩套樣式肯定不行。 那麼我們該採取宣告方案解決呢? 前提條件:頁面 b **實現與 theme 主題強耦合 方案1:重寫頁面 b 改用 theme.light 主題 方案2:仿寫 theme.light 系統效果 方案3:頁面 b alertdailog 採用 theme.light 的彈出框樣式 綜合考慮 方案1不僅工作量大而且還會破壞原始**,可能會引入新問題。方案2新增工作量。方案3工作量小,可行性未知。

作為喜歡挑戰的程式設計師當然選擇方案3,我們來理清楚思路。 1.找到 theme.light 主題下 alertdailog 引用的 style 2.在 alertdailog.builder 建立的時候指定 style ( theme )

進入 theme.light 查詢到與 alertdialog 相關的屬性

再找 alertdailog 過程中發現父類 dailog 寫明了引用的 attr 名

嘗試直接引用 @style/theme.dialog.alert 你會發現 as 會提示該資源非 public 無法被引用, 然後我去\platforms\android-23\data\res\values\public.xml查詢這個屬性是否被宣告,搜尋確實沒有被宣告。 此時遇到了乙個問題,我無法拿到 theme.light 下私有的 theme.dialog.alert 資源 id 。

最終經過重重波折,想到了從 a 頁面獲取 theme 呼叫 resolveattribute 解析出 theme.dialog.alert 的資源 id ,然後放到靜態變數裡。當需要 alertdailog 的時候就直接用這個解析出來的 theme.dialog.alert 資源 id 。 注意前提是提前解析到這個資源 id ,否則它解析失敗彈出的效果還是主題預設的 dialogtheme 效果。

主 a 頁面

public static int holodialogthemeid=0;

....

final typedvalue outvalue = new typedvalue();

gettheme().resolveattribute(android.r.attr.alertdialogtheme, outvalue, true);

holodialogthemeid = outvalue.resourceid;

複製**

彈出框使用

alertdialog.builder builder=new alertdialog.builder(context,holodialogthemeid);

...複製**

jquery ajax跨域呼叫其他系統的URL

場景模擬,現有公司a中的內網系統oa 需呼叫公司b中的部署在外網的系統url 由於公司a中的系統是內網系統,其所部屬在的伺服器是不能訪問外網的。但公司a中的員工通過安全認證後,客戶端瀏覽器是可以訪問外網的。鑑於此種環境,首先考慮在oa系統中的jsp頁面中通過jquery ajax非同步呼叫公司b的外...

thinkphp 跨模組呼叫

專案簡介 測試專案名為tp3.0 訪問 localhost tp3.0 安裝環境 windows apache mysql php 模組分組 測試時將模組分為兩組home,admin,根據需求還可以新增更多分組,比如 home,admin,user,article。一 跨模組呼叫例項 簡介 在ind...

C 跨執行緒呼叫

問題 執行一下 報錯 大概意思就是跨執行緒操作,label沒法兒賦值 1.private void mainloop 8.解決方案 一 在5 6行中間新增以下 checkforillegalcrossthreadcalls false 禁止編譯器對跨執行緒訪問做檢查 二 使用deletgate in...