android Theme使用二

我的Android进阶之旅------>解决错误:You need to use a Theme.AppCompat theme (or descendant) with this activity. 1、错误描述今天,想实现Activity不显示标题栏的效果,在项目的AndroidManifest.xml文件,对相应的Activity添加属性 android:theme="@android:style/Theme.NoTitleBar"具体代码如下: 阅读详情

以前我们布局的时候使用一个属性都是android:开头。这是表示我们使用的是android自带的属性,那我们在attrs.xml中定义的数据怎么引用呢?

1.2.2使用自定义的属性

1)、在res/values文件下定义一个attrs.xml文件,代码如下:

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

<resources>

   <declare-styleable name="ToolBar">

       <attr name="buttonNum" format="integer"/>

       <attr name="itemBackground"format="reference|color"/>

</declare-styleable>

<attrname="buttonindex" format=" reference "/>

</resources>

 

2)、在布局xml中如下使用该属性:

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

<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"

   xmlns:toolbar="http://schemas.android.com/apk/res-auto"

   android:layout_width="fill_parent"

   android:layout_height="fill_parent" >

<cn.zzm.toolbar.ToolBar

              android:id="@+id/gridview_toolbar"

       android:layout_width="fill_parent"

       android:layout_height="wrap_content"

       toolbar:buttonNum="5"

       toolbar:itemBackground="@drawable/control_bar_item_bg"/>

</RelativeLayout>

注意:xmlns:toolbar=”http://schemas.android.com/apk/res-auto”表示自定义的名字空间,等号后面是固定的,在以前的android版本中自定义名字空间不是这样的。现在统一了。

 

 

3)、在自定义组件中,可以如下获得xml中定义的值:

TypedArray a = context.obtainStyledAttributes(attrs,R.styleable.ToolBar);

buttonNum =a.getInt(R.styleable.ToolBar_buttonNum, 5);

itemBg =a.getResourceId(R.styleable.ToolBar_itemBackground, -1);

a.recycle();

 

注意:代码里面获取一个属性的值规则。R.styleable.+ <declare-styleable name="ToolBar">+下划线+属性名称(<attrname="buttonNum">)

如上面的a.getInt(R.styleable.ToolBar_buttonNum,5);

 

TypedArray 有很多getxxx方法,可以帮我们获取值:



代码里面使用属性是很常见的,特别是在看android源码的时候,android中的view及其子类都使用了这种方式。这有什么好处呢?这种方式更灵活,可以让我们动态的改变view的显示方式,比如字体大小,字体颜色,背景图片。无需改变代码只需要改变资源文件就可以达到各种效果。


Matlab波动光光学系统 波动光学是一种研究光波传播过程的理论,按照其处理的信息类型不同,可以分为相干和非相干波动光学,相干波动光学可以用作特定光学系统的分析和设计,其主要依赖物理光学和电磁波的基本原理,以及光学干涉和衍射的经验方程式,其中光波传播过程是以复数形式表示的,包括振幅和相位两个方面。近年来光学技术得到了广泛的应用和发展,波动光光学系统是其中一种重要的光学系统,它主要是利用波动光学原理,通过计算机模拟实现各种光学系统的设计、分析和优化,可应用于大气光传输、光束整形、分析系统的衍射和干涉特性,包括利用。 阅读详情

相关推荐

四足机器人——机械结构

目录 一、四足机器人腿型: 1、并联腿 2、串联腿 3、 腿的布局(关节配置) 二、四足机器人足端设计: 三、四足机器人膝关节驱动: 1、皮带轮驱动: 2、四连杆或者推杆驱动 四、四足机器人机械整体结构设计细节 一、四足机器人腿型: 1、并联腿 优点:受力角度来说,并联腿比串联腿好,并联腿较为灵活。 2、串联腿 优点:运动范围大 3、 腿的布局(关节配置) 为了使机器人具有较好的稳定性,一般会采用比较低的重心。这就导致了机器人腿的髋关节位置需要位于机器人身体的两侧..

m0_58585940的博客 3万+

主题引用

最简单的更改全局样式的方式,是直接采用颜色主题(theme)。例如,在示例集合中,可以选择 “Theme”,直接看到采用主题的效果。 ECharts4 开始,除了一贯的默认主题外,新内置了两套主题,分别为'light'和'dark'。可以这么来使用它们: var chart = echarts.init(dom, 'light'); 或者 var chart = ech...

359

Unity Hub报错The Hub as encountered a critical error and must close

如果注册表HKEY_LOCAL_MACHINE\SOFTWARE\Unity Technologies\这个目录下有Hub文件,直接删掉然后重装就可以。C:\Users\Administrator\AppData\Roaming\Unity 作者:SevenVee。HKEY_CURRENT_USER\Software\Unity 下所有项,尝试过,卸载重装,清除临时文件无果后,最终决定删除所有与Hub有关的文件。重装unity后可以打开了。结果:卸载重装后还是会出现此问题。结果:重装后还是无法解决。

qq_42345116的博客 3638

总结一下Android中主题(Theme)的正确玩法

在AndroidManifest.xml文件中有<application android:theme="@style/AppTheme">,其中的@style/AppTheme是引用的res/values/styles.xml 中的主题样式,也有可能是引用的 res/values-v11/styles.xml 或者 res/values-v14/styles.xml,这是根据运行此程序...

weixin_30653097的博客 4536

病理组学分析系列教程1:使用Python-histolab进行病理图像预处理,tiles切片自动生成

病理图像tiles自动生成,WSI图像预处理

qq_43449643的博客 1741

MATLAB三元相图实战:从数据准备到高级可视化技巧全解析

本文深入解析了如何使用MATLAB绘制专业的三元相图(ternary plot)。文章从数据归一化、范围映射等预处理技巧入手,详细介绍了散点图、等高线图、凸包计算等高级可视化方法,并提供了多数据集对比与出版级图表美化的实战指南,帮助科研与工程人员高效呈现复杂的三元数据关系。

spark7igniter的博客 258

Android Material Design-Using the Material Theme(使用Material主题)-(二)

转载请注明出处:   新的material主题提供了: l  可以让你设置调色板的系统控件。 l  为控件(设计的)触摸反馈动画。 l  Activity过渡动画   你可以根据调色板,控制你定制的material主题。你也可以调整标题栏(Action Bar),并使用主题属性的状态栏,如图三。   提供的系统控件有了全新的设计和触摸反馈动画。你可以在app中自定义调色板,触摸反

Rocko's blog - http://rocko.xyz 7554

基于FFT的阵列方向图快速计算公式推导

因为自己毕设涉及到阵列方向图综合相关知识,最近阅读了关于方向图综合的相关文献,就其中关于使用FFT计算阵列方向图的方法进行了公式推导。 简介: 自从1965年Colley-Tukey发表快速傅里叶变换[1]论文以来,FFT在许多科学技术领域获得了广泛和成功的应用。在阵列信号处理与雷达信号处理领域,随着科技的发展,对于电尺寸较大的相控阵天线,使用公式按照级数求和计算天线阵列方向图的方法效率甚低,...

qq_38151438的博客 4292

Android使用自定义标签栏报错: IllegalStateException: You need to use a Theme.AppCompat theme

创建的项目中或者有修改相关的配置文件,最容易出现这个问题,他的意思很简单就是你当前使用的皮肤theme不是我需要的,从错误可以看出她需要的皮肤是Theme.AppCompat;出现这个错误的原因是因为我们创建的activity有两个来源:一个是来自Android.app.actiivty的包;另一个是由于来源于v7jar包中的android.support.v7.app.AppCompatActivity包下,不同的包需要的皮肤也不同。 针对这种我们的解决办法也有两种如下: 方法一:将自...

天涯芳草 592

基于STM32设计的水下水质检测装置(微信小程序)(205)

本项目设计了一款基于STM32微控制器为核心的水下水质检测设备,该设备具有高度集成化、智能化的特点,能够实时监测水深、温度、浊度及溶解性总固体(TDS)等关键水质参数,并通过4G网络将数据上传至腾讯云IOT物联网平台,实现远程监控和数据分析。同时,为了便于操作和移动观测,还配套开发了微信小程序,用户可通过微信小程序实时查看并控制设备的各项功能,如调整下潜深度等。

1252

手把手教你学RDMA驱动开发专栏--第7章 队列对(QP)与数据传输实现​7.3 完成队列(CQ):事件通知机制与轮询/中断模式

本章详细探讨了RDMA驱动中完成队列(CQ)的事件通知机制,重点分析了轮询与中断两种模式的实现原理及优化策略。CQ作为操作结果的报告载体,其核心功能包括结果反馈、事件通知和资源同步。轮询模式通过主动查询实现低延迟,适合高性能场景;中断模式通过被动通知节省CPU资源,适用于低频事件处理。驱动实现需考虑CQ溢出防护、多QP共享同步等关键问题,并提供事件通道机制将CQE传递给用户态。通过对比两种模式的优缺点及适用场景,揭示了RDMA系统在性能与资源间的权衡机制。

MHD0815的博客 396

解决android:theme="@android:style/Theme.NoDisplay" 加入这句话后程序不能运行

  原因: 原来用的是ActionBarActivity,继承自 ActionBarActivity的类必须指定固定的集中Theme风格,而这些 Theme 风格是需要导入V7中的 appcompat LIB库工程,编译后再引用才能引用使用。  解决1:  将E:\android\adt-bundle-windows-x86-20131030\sdk\extras\android\suppo...

weixin_34253539的博客 2422

OpenClaw部署太难?汉化版+中文社区+国产替代品,国内用户零门槛指南

OpenClaw作为GitHub 10万+星的开源AI助手平台,近期在国内AI圈备受关注 🌟 但部署难度和英文界面让很多用户望而却步。本文整理了针对国内用户的友好资源和简便替代方案,帮助国内用户零门槛上手AI助手工具 🚀

XiaoqiangClub的博客 5758

Android:bug记录(简单)

2、在使用Toolbar的theme中需要使用android:Theme.Material.Light.NoActionBar的子项,需要实现的item为windowActionBar,将其设置为false,因为windowActionBar与Toolbar两个控件实现的同一个功能效果。1、activity继承AppCompatActivity,使用theme需要为Theme.AppCompat的子项。重新定义theme并修改activity中的theme。3、两者之间存在冲突,需要重新定义。

qq_51108920的博客 442

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

You need to use a Theme.AppCompat theme (or descendant) with this activity.

说明你的 Activity 正在使用需要支持库主题(如。)的组件,但你没有为它指定基于。

xueyoubangbang的博客 2677

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

You need to use a Theme.AppCompat theme (or descendant) with this activity. 完美解决

先看一条错误信息:Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. android Studio在执行新建项目时出现此错误,出现此错误的原因就是: Activty继承自android.support.v7...

lizhong 7万+

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

com.google.android.material.card.MaterialCardView报错问题解决

这是因为material:1.1.0以后,部分Material控件需要MaterialComponents包下的theme才支持,而新建项目默认使用的还是Theme.AppCompat包,我们手动改成Theme.MaterialComponents即可。 第二种解决办法: 加上这一句 <com.google.android.material.card.MaterialCardV...

wxx314165038的博客 2985

android的小疑点:You need to use a Theme.AppCompat theme

android的小问题:You need to use a Theme.AppCompat theme android的一个小问题:   Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

JokAr 937

关于新版SDK报错You need to use a Theme.AppCompat theme的两种解决办法 - 转

android的一个小问题: Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. 法一: 当在AndroidManifest.xml文件的application的节点设置了属性: and...

weixin_30416871的博客 1031

android 列表底部弹出框,Android 底部弹出提示框的解决办法(使用Activity以及PopupWindow)...

本片文章主要谈探讨了如何实现在底部弹出提示框背景为半透明效果的实现。想要实现此种效果一般有两种方式一个是使用Activity设置Theme另一种方式就是使用PopupWindow设置样式实现效果。一,使用Activity首先是此activity的布局文件:xmlns:android="http://schemas.android.com/apk/res/android"android:layout...

weixin_28951059的博客 1121

Android开发如何去除标题栏title

虽然是一个小问题,今天遇到了,也就写下来吧。防止自己忘掉。 取消标题栏的方式有两种,一种是在代码添加,另一种是在AndroidManifest.xml里面添加。 1、在代码中实现:在此方法setContentView(R.layout.main)之前加入:requestWindowFeature(Window.FEATURE_NO_TITLE);标题栏就没有了。 2、在AndroidM...

weixin_34128534的博客 181

Android You need to use a Theme.AppCompat theme (or descendant) with this activity.

错误描述为:java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.起因:我想在Manifest中设置我的activity全屏,代码如下: <activity android:name=...

weixin_30902675的博客 84

Android异常:No resource found that matches the given name 'Theme.AppCompat.Light'解决方法

解决方法一:重新新建android项目如下图所示选择版本。 解决方法二: 查看 res/values/styles.xml 下的报错点。  &lt;style name="AppBaseTheme" parent="Theme.AppCompat.Light"&gt; 把这个改成 &lt;style name="AppBaseTheme" parent="android:Them...

未曾远去 1万+
上一篇: android Theme使用一
下一篇: android Theme使用三
dalancon
博客等级 码龄15年 189粉丝 67原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值