java如何让布局器透明_关于java:如何在Android Android 6.0(Marshmallow)上创建透明布局?...

本问题已经有最佳答案,请猛点这里访问。

以下示例显示了在Android上使活动透明的简单方法。

[参考:http://www.coderzheaven.com/2011/07/20/how-to-create-a-transparent-activity-in-android/]

我的活动:

public class TranslucentActivity extends Activity {

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

}

}

现在主要的布局文件main.xml:

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

>

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="@string/hello"

android:textColor="@drawable/red"

android:textStyle="bold"

/>

android:text="This is Translucent Activity Demo From CoderzHeaven"

android:id="@+id/Button01"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textColor="@drawable/red"

android:textStyle="bold">

好的,现在这里是必须应用于使活动透明的样式。在res/values文件夹中创建名为style.xml的文件,并将此代码复制到其中:

true

@android:color/transparent

@null

true

true

false

现在应该在哪里应用这个主题?它应用于AndroidManifest.xml

该文件如下所示。

package="pack.coderzheaven"

android:versionCode="1"

android:versionName="1.0">

android:theme="@style/Theme.Transparent"

android:label="@string/app_name">

检查应用此样式的清单中的此行。

机器人:主题=" @风格/ Theme.Transparent"

appname和不同的颜色位于strings.xml中

TranslucentActivity! From Coderzheaven

TranslucentActivity

#ffffff

#000000

#2554C7

#347C2C

#ff9900

#FF00FF

#a020f0

#778899

#C11B17

#FFFF8C

#b0e0e6

#2F1700

#7D2252

Select Category

#606060

输出:抛出异常:java.lang.IllegalStateException:您需要将Theme.AppCompat主题(或后代)与此活动一起使用。

有什么建议吗?有解决方案吗我该如何解决这个问题?

但我的目标布局是透明的。

我得到了解决方案

如何在Android上创建透明活动?

With the"AppCompat" library or"Android Design Support Library" it's a bit different:

In the styles.xml:

#33000000

true

@android:color/transparent

@null

true

@android:style/Animation

In the AndroidManifest.xml:

android:name=".WhateverNameOfTheActivityIs"

android:theme="@style/Theme.AppCompat.Translucent"

...

只需将样式Theme.Transparent的父主题更改为Theme.AppCompat即可

将扩展活动更改为AppCompatActivity

使用AppCompatActivity扩展您的活动

public class TranslucentActivity extends AppCompatActivity

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值