小编Lif*_*fes的帖子

您是否需要为 AdView 显式调用暂停、恢复、销毁?

AdView 是自动绑定到活动生命周期还是必须显式调用pause, resume,destroy事件?它是否取决于 AdView 的大小?我正在使用横​​幅广告。

我找不到很多其他人这样做的代码示例,主要的 Android 帮助文章也没有提到它(他们只是在 onCreate 中加载广告,不做任何其他事情)。

https://developers.google.com/android/reference/com/google/android/gms/ads/AdView (代码示例包括 pause/resume/destroy 并在方法说明中提到我们“应该调用这些方法”,但是不详述)。

https://developers.google.com/admob/android/banner (没有提到需要暂停/恢复/销毁)。

http://thetechnocafe.com/a-complete-guide-to-integrating-admob-in-your-android-app/ (暂停并销毁代码中的视频广告,但没有提及原因或给出任何解释)

<LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

    <!-- app content -->

    <com.google.android.gms.ads.AdView
            xmlns:ads="http://schemas.android.com/apk/res-auto"
            android:id="@+id/myAdView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            ads:adSize="BANNER"
            ads:adUnitId="ca-app-pub-3940256099942544/6300978111">
    </com.google.android.gms.ads.AdView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
public class MainActivity extends AppCompatActivity {
    private AdView mAdView;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // ...

        mAdView = findViewById(R.id.myAdView);
        AdRequest adRequest = new AdRequest.Builder().build();
        mAdView.loadAd(adRequest);
    }

    // do I need this code as well???
    @Override
    public …
Run Code Online (Sandbox Code Playgroud)

android ads admob android-lifecycle

9
推荐指数
1
解决办法
984
查看次数

Android全屏粘沉浸式模式-如何更改导航栏背景或图标颜色?

我按照Android 开发教程操作并获得了全屏粘性沉浸模式。这使得状态栏和导航栏隐藏,直到用户从底部向上或从顶部向下滑动,此时它们会出现并在不使用时慢慢淡出。

问题出在 Android 10(可能还有其他版本)上:屏幕底部的导航栏只是白色图标。没有透明的黑色背景。这使得使用浅色用户界面很难看清。

有没有办法改变导航栏的背景或图标颜色?特别是粘性的沉浸式导航栏,它会出现并消失(因为它太轻,无法与浅色 UI 一起使用)。

我尝试过以编程方式设置样式和颜色,但它们仅在非全屏模式下工作:

<!-- does not work -->
<item name="android:navigationBarColor">@android:color/white</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:windowLightNavigationBar">true</item>
Run Code Online (Sandbox Code Playgroud)

我也尝试过聆听,OnSystemUiVisibilityChangeListener这样我就可以在导航栏后面显示我自己的透明栏,但它不会触发粘性沉浸模式(如本 SO 帖子和视频中所述):

使用粘性沉浸模式检测系统用户界面何时可见

https://www.youtube.com/watch?v=cBi8fjv90E4&feature=youtu.be&t=6m56s

设置全屏的活动代码(kotlin):

protected fun isFullscreen() = defaultSharedPref.getBoolean(SharedPreferenceKey.IS_FULL_SCREEN, false)

private fun supportsFullscreenMode(): Boolean {
    return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT
}

override fun onWindowFocusChanged(hasFocus: Boolean) {
    super.onWindowFocusChanged(hasFocus)
    if (hasFocus && isFullscreen()) toggleFullScreenMode(true)
}

/**
 * "sticky immersive" full screen mode.
 * When user swipes from top/bottom edge, transparent status bar and navigation bar appear and …
Run Code Online (Sandbox Code Playgroud)

android fullscreen navigationbar android-immersive

6
推荐指数
0
解决办法
2384
查看次数

Android 某些 EditText 字段不响应长按(API 30+,layout_width 0dp)

我想知道是否还有其他人经历过这个奇怪的错误。我的布局很复杂,但本质上它是带有 EditText 字段的成排视图持有者。

在我将目标 SDK 更新到 API 30 之前,它一直完美运行。

针对 API 30 后,我的一些EditText 字段不响应“焦点触摸事件”(光标手柄不显示,无法长按,也无法选择任何文本)。您仍然可以在字段中输入内容并通过点击移动光标。同样,某些文本字段工作得很好,而其他文本字段则受到此错误的影响。

在此输入图像描述

^ 该图像不是我的应用程序,只是为了显示光标处理程序以供理解。

约束布局和线性布局都有同样的bug。

<!-- in constraint layout -->
<androidx.appcompat.widget.AppCompatEditText
    android:id="@+id/myTextField"
    android:layout_height="wrap_content"
    android:layout_width="0dp"
    app:layout_constraintHorizontal_weight="1"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintBottom_toBottomOf="parent"/>

<!-- in linear layout -->
<androidx.appcompat.widget.AppCompatEditText
    android:id="@+id/myTextField"
    android:layout_height="wrap_content"
    android:layout_width="0dp"
    android:layout_weight="1"/>
Run Code Online (Sandbox Code Playgroud)

如果我将文本字段宽度更改为wrap_content它,它对于所有文本字段都适用,但这不适合我的设计。我需要文本字段来填充可用空间。

我什至尝试手动将宽度设置为随机 dp 值,但它仍然不起作用。

我已经在 < API 30 设备上进行了测试,一切都很好。

我也有用户在生产中报告过这个问题。

我错过了什么?为什么这不适用于 API 30+?

还有另一种方法可以让 EditText 字段填充空间吗?

更新(仍未解决):

我已将 Android Studio 更新到最新版本Arctic Fox 2020.3.1.。我还将 gradle 更新为7.0.3,将 kotlin 更新为1.5.31,并将我的所有库更新为最新版本。我正在使用 …

android android-appcompat android-edittext android-wrap-content android-api-30

5
推荐指数
1
解决办法
318
查看次数

MS Visio 2007:如何将基数显示在关系的两端?

在Visio 2007中,我似乎只能设置父子关系的基数,但我也想设置Child-to-Parent.Visio不会让我这样做吗?我需要创建一个单独的关系来实现这一目标吗?我正在使用两个Entity对象/形状和一个Relationship对象/形状.

注意:我通过"数据库">"选项">>"文档"并选中"基数"框,将基数显示在图表上.

visio cardinality

3
推荐指数
1
解决办法
2万
查看次数

GridView RowDataBound处理程序 - 无法从行获取数据

我有一个匿名类型的GridView.我需要检查单元格中的值,并在满足条件时突出显示该单元格.问题是,当我尝试从行的单元格中提取数据时,我总是得到一个空字符串.我已成功突出显示所有单元格,并且已在Visual Studio 2010调试器中检查并确认Row具有数据(行的DataItem具有我需要的值).这是在PostBack上发生的,我不确定这是不是问题.

这是我尝试过的代码和解决方案:

protected void grvValidCourses_RowDataBound(Object sender, GridViewRowEventArgs e) {
 if (e.Row.RowType == DataControlRowType.DataRow) {
  String str = e.Row.Cells[6].Text.ToString(); // empty string
  Label lbl = (Label) grvValidCourses.FindControl("lblEndDate"); // null
  DataRowView rowView = (DataRowView)e.Row.DataItem; // exception about casting anonymous type
Run Code Online (Sandbox Code Playgroud)

这里发生了什么?为什么我不能从细胞中获取数据?

GridView的标记:

 <asp:GridView ID="grvValidCourses" runat="server" Width="790px" OnRowCancelingEdit="grvValidCourses_RowCancelingEdit"
                    OnRowEditing="grvValidCourses_RowEditing" OnRowUpdating="grvValidCourses_RowUpdating" OnRowDeleting="grvValidCourses_RowDeleting"
                    AutoGenerateColumns="False" OnSelectedIndexChanged="grvValidCourses_SelectedIndexChanged"
                    OnRowDataBound="grvValidCourses_RowDataBound" >
                    <Columns>
                        <asp:CommandField ShowEditButton="True" EditText="Edit" UpdateText="Update |" />
                        <asp:TemplateField ShowHeader="False">
                             <ItemTemplate>
                               <asp:LinkButton ID="lbnDelete" runat="server" CausesValidation="False" CommandName="Delete"
                                    Text='<%# (Eval("active") == null ? "Delete" : ((Eval("active").ToString() == "0" ? …
Run Code Online (Sandbox Code Playgroud)

.net c# asp.net gridview

3
推荐指数
1
解决办法
4万
查看次数

C#是否有内置函数将格式化的String转换回Number?

如何将格式化数字的字符串转换回数字?

  Decimal percent = 55.76;
  String strPercent = String.Format("{0:0.0}%", percent);
  Decimal dollars = 33.5;
  String strDollars = String.Format("{0:C}", dollars);
Run Code Online (Sandbox Code Playgroud)

稍后说,我希望得到百分比和美元价值,作为数字.有没有内置的方法来使用C#和asp.net做到这一点?我知道我如何使用正则表达式和一个字符串函数,但我从http://msdn.microsoft.com/en-us/library/ks098hd7(vs.71).aspx读到了一个Decimal.Parse()函数.

是否有内置函数来执行此操作?如果是,我该如何使用它?

c# asp.net format numbers

2
推荐指数
2
解决办法
2613
查看次数

如何通过WCF Web服务序列化和发送MailMessage?

我想将MailMessage作为参数传递给我的WCF Web服务.问题是MailMessage不可序列化,并且很多属性(如MailAddress)也不可序列化.我该如何序列化?

我已经看到了一个教程,通过将它作为包装类中的属性来序列化它,但这并没有帮助我通过WCF发送它,因为MailMessage属性没有出现在客户端(因为它不可序列化) .我不想只发送基本字符串值(to,from,body).我想发送整个MailMessage及其所有属性.我怎样才能做到这一点?

更新:

我认为使用Web服务并序列化MailMessage类是不值得的.序列化类确实有效,但是很多方法/构造函数在WCF客户端/消费者上都不可用.所以我不得不重新编写代码,从常规类(例如MailMessage)转换到客户端的序列化类(例如SerializedMailMessage).

我决定使用EmailHelper创建一个类库,并使用调用应用程序的配置来确定SMTP设置.

SmtpSection smtpConfig = ConfigurationManager.GetSection("system.net/mailSettings/smtp") as SmtpSection;
if (smtpConfig != null) {
    // extract values to your SmtpClient
}
Run Code Online (Sandbox Code Playgroud)

c# serialization web-services mailmessage

2
推荐指数
1
解决办法
3446
查看次数