草庐IT

android - 自定义对话框无法正常出现

coder 2024-07-05 原文

在我的应用程序中,我尝试制作自定义对话框,所以我为此编写了一个 XML,在我的 XML 中它看起来像这样,

对话框.xml,

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

<RelativeLayout android:layout_width="fill_parent" 
                android:layout_height="50.0dip" 
                android:layout_marginTop="5.0dip"
                android:layout_margin="5.0dip">

    <TextView android:id="@+id/textViewOTPDialogMessage" android:text="@string/OTPDialogActivityMessage" android:gravity="center" android:textStyle="bold" android:textColor="#ff4d4d4d" 
       android:layout_width="wrap_content" android:textSize="18dp"
       android:layout_height="wrap_content"   
       android:layout_centerVertical="true" />

    <View android:layout_marginTop="1.0dip" android:layout_below="@+id/textViewOTPDialogMessage" android:layout_width="fill_parent" android:layout_height="1dp" android:background="@android:color/darker_gray"/>

</RelativeLayout>


<RelativeLayout android:layout_width="fill_parent" android:layout_height="50.0dip" android:layout_marginTop="5.0dip">

   <TextView android:text="E-Mail Id OTP* " android:id="@+id/textViewEmailOTP" android:textStyle="bold" android:textColor="#ff4d4d4d" 
       android:gravity="left"  android:layout_width="wrap_content" 
       android:layout_height="wrap_content"  android:layout_marginLeft="10.0dip" android:layout_alignParentLeft="true" 
       android:layout_centerVertical="true" />

   <EditText  
       android:id="@+id/editTextEmailIdOtp" android:background="@drawable/custom_edittext" 
       android:paddingLeft="5.0dip" android:layout_width="fill_parent" android:layout_height="35.0dip" 
       android:layout_marginLeft="150.0dip" android:layout_marginRight="10.0dip" 
       android:singleLine="true" android:layout_alignParentLeft="true" 
       android:layout_centerVertical="true" android:imeOptions="actionNext" />

</RelativeLayout>

<RelativeLayout android:layout_width="fill_parent" android:layout_height="50.0dip">

   <TextView android:text="Mobile OTP* " android:id="@+id/textViewMobileOTP" android:textStyle="bold" android:textColor="#ff4d4d4d" 
       android:gravity="left" android:layout_width="wrap_content" 
       android:layout_height="wrap_content"  android:layout_marginLeft="10.0dip" android:layout_alignParentLeft="true" 
       android:layout_centerVertical="true" />

   <EditText  
       android:id="@+id/editTextMobileOtp" android:background="@drawable/custom_edittext" 
       android:paddingLeft="5.0dip" android:layout_width="fill_parent" android:layout_height="35.0dip" 
       android:layout_marginLeft="150.0dip" android:layout_marginRight="10.0dip" 
       android:singleLine="true" android:layout_alignParentLeft="true"
       android:layout_centerVertical="true" android:imeOptions="actionNext" />

</RelativeLayout>


<Button android:id="@+id/btnValidate" android:text="Validate" android:textSize="18.0sp" android:textStyle="bold" android:textColor="#ff4d4d4d"
    android:layout_gravity="center_horizontal" android:layout_width="wrap_content" 
    android:layout_height="wrap_content" android:layout_marginTop="10.0dip" android:layout_marginBottom="10.0dip" />


</LinearLayout>

然后当我在我的设备上运行它时,

它是这样来的,

我试图以编程方式增加对话框的宽度大小,但没有任何区别,

    private void callOTPDialog() 
    {
    Dialog myDialog = new Dialog(this);
    myDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    myDialog.getWindow().setLayout(600, 400);
    myDialog.setContentView(R.layout.otpdialog);
    myDialog.setCancelable(false);
    Button btnValidate = (Button) myDialog.findViewById(R.id.btnValidate);

    EditText email = (EditText) myDialog.findViewById(R.id.editTextEmailIdOtp);
    EditText mobile = (EditText) myDialog.findViewById(R.id.editTextMobileOtp);
    myDialog.show();

    btnValidate.setOnClickListener(new OnClickListener()
    {

       @Override
       public void onClick(View v)
       {
               //your login calculation goes here
       }
   });


}

在 XML 中我已经提到了这些行,

android:layout_width="fill_parent"
android:layout_height="wrap_content"

然后也不知道这里发生了什么。

现在要做什么,

请帮忙,

谢谢。

最佳答案

尝试如下:

LayoutInflater factory = LayoutInflater.from(Splash.this);

View DialogView = factory.inflate(
            R.layout.custom_progress_layout, null);

Dialog main_dialog = new Dialog(Splash.this,R.style.Theme_Dialog);
main_dialog.setContentView(DialogView);
main_dialog.show();

并在 values\styles.xml 中创建 Theme_Dialog

  <style name="Theme_Dialog" parent="android:Theme.Holo.Dialog">
    <item name="android:backgroundDimEnabled">false</item>
    <item name="android:layout_width">fill_parent</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowBackground">@android:color/transparent</item>
</style>

这对我来说是完美的。

更新:您只需将 RelativeLayout 属性宽度与 android:layout_width="wrap_content" 更改为您的 布局.xml

关于android - 自定义对话框无法正常出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21902735/

有关android - 自定义对话框无法正常出现的更多相关文章

  1. ruby - Facter::Util::Uptime:Module 的未定义方法 get_uptime (NoMethodError) - 2

    我正在尝试设置一个puppet节点,但ruby​​gems似乎不正常。如果我通过它自己的二进制文件(/usr/lib/ruby/gems/1.8/gems/facter-1.5.8/bin/facter)在cli上运行facter,它工作正常,但如果我通过由ruby​​gems(/usr/bin/facter)安装的二进制文件,它抛出:/usr/lib/ruby/1.8/facter/uptime.rb:11:undefinedmethod`get_uptime'forFacter::Util::Uptime:Module(NoMethodError)from/usr/lib/ruby

  2. ruby-on-rails - 由于 "wkhtmltopdf",PDFKIT 显然无法正常工作 - 2

    我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-

  3. ruby-on-rails - 无法使用 Rails 3.2 创建插件? - 2

    我对最新版本的Rails有疑问。我创建了一个新应用程序(railsnewMyProject),但我没有脚本/生成,只有脚本/rails,当我输入ruby./script/railsgeneratepluginmy_plugin"Couldnotfindgeneratorplugin.".你知道如何生成插件模板吗?没有这个命令可以创建插件吗?PS:我正在使用Rails3.2.1和ruby​​1.8.7[universal-darwin11.0] 最佳答案 随着Rails3.2.0的发布,插件生成器已经被移除。查看变更日志here.现在

  4. ruby-on-rails - Rails 3.2.1 中 ActionMailer 中的未定义方法 'default_content_type=' - 2

    我在我的项目中添加了一个系统来重置用户密码并通过电子邮件将密码发送给他,以防他忘记密码。昨天它运行良好(当我实现它时)。当我今天尝试启动服务器时,出现以下错误。=>BootingWEBrick=>Rails3.2.1applicationstartingindevelopmentonhttp://0.0.0.0:3000=>Callwith-dtodetach=>Ctrl-CtoshutdownserverExiting/Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/actionmailer-3.2.1/lib/action_mailer

  5. ruby - 无法运行 Rails 2.x 应用程序 - 2

    我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby​​:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r

  6. ruby-on-rails - 无法在centos上安装therubyracer(V8和GCC出错) - 2

    我正在尝试在我的centos服务器上安装therubyracer,但遇到了麻烦。$geminstalltherubyracerBuildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingtherubyracer:ERROR:Failedtobuildgemnativeextension./usr/local/rvm/rubies/ruby-1.9.3-p125/bin/rubyextconf.rbcheckingformain()in-lpthread...yescheckingforv8.h...no***e

  7. ruby-on-rails - form_for 中不在模型中的自定义字段 - 2

    我想向我的Controller传递一个参数,它是一个简单的复选框,但我不知道如何在模型的form_for中引入它,这是我的观点:{:id=>'go_finance'}do|f|%>Transferirde:para:Entrada:"input",:placeholder=>"Quantofoiganho?"%>Saída:"output",:placeholder=>"Quantofoigasto?"%>Nota:我想做一个额外的复选框,但我该怎么做,模型中没有一个对象,而是一个要检查的对象,以便在Controller中创建一个ifelse,如果没有检查,请帮助我,非常感谢,谢谢

  8. ruby - 主要 :Object when running build from sublime 的未定义方法 `require_relative' - 2

    我已经从我的命令行中获得了一切,所以我可以运行rubymyfile并且它可以正常工作。但是当我尝试从sublime中运行它时,我得到了undefinedmethod`require_relative'formain:Object有人知道我的sublime设置中缺少什么吗?我正在使用OSX并安装了rvm。 最佳答案 或者,您可以只使用“require”,它应该可以正常工作。我认为“require_relative”仅适用于ruby​​1.9+ 关于ruby-主要:Objectwhenrun

  9. ruby - 无法让 RSpec 工作—— 'require' : cannot load such file - 2

    我花了三天的时间用头撞墙,试图弄清楚为什么简单的“rake”不能通过我的规范文件。如果您遇到这种情况:任何文件夹路径中都不要有空格!。严重地。事实上,从现在开始,您命名的任何内容都没有空格。这是我的控制台输出:(在/Users/*****/Desktop/LearningRuby/learn_ruby)$rake/Users/*******/Desktop/LearningRuby/learn_ruby/00_hello/hello_spec.rb:116:in`require':cannotloadsuchfile--hello(LoadError) 最佳

  10. ruby - 无法覆盖 irb 中的 to_s - 2

    我在pry中定义了一个函数:to_s,但我无法调用它。这个方法去哪里了,怎么调用?pry(main)>defto_spry(main)*'hello'pry(main)*endpry(main)>to_s=>"main"我的ruby版本是2.1.2看了一些答案和搜索后,我认为我得到了正确的答案:这个方法用在什么地方?在irb或pry中定义方法时,会转到Object.instance_methods[1]pry(main)>defto_s[1]pry(main)*'hello'[1]pry(main)*end=>:to_s[2]pry(main)>defhello[2]pry(main)

随机推荐