标签: android-xml

试图生成一个简单的弹出窗口

我试图在点击按钮时生成一个简单的弹出窗口,但由于某种原因它无法正常工作.以下是我的代码:

     public class Product extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    //overridePendingTransition(R.anim.fadein, R.anim.fadeout);
    setContentView(R.layout.product);
    String fontPath = "fonts/georgia.ttf";
    Typeface tf = Typeface.createFromAsset(getAssets(), fontPath);

    final Animation animScale = AnimationUtils.loadAnimation(this, R.anim.anim_scale);


    Button Particle =(Button)findViewById(R.id.button1); 
    Button MDF=(Button)findViewById(R.id.button2);
    Button Laminates=(Button)findViewById(R.id.button3);
    Button Ply =(Button)findViewById(R.id.button4); 
    Button Floor=(Button)findViewById(R.id.button5);
    Button Door=(Button)findViewById(R.id.button6);
    Button EdgeBand=(Button)findViewById(R.id.button7);
    Button ModFur=(Button)findViewById(R.id.button8);



    Particle.setTypeface(tf);
    MDF.setTypeface(tf);
    Laminates.setTypeface(tf);
    Ply.setTypeface(tf);
    Floor.setTypeface(tf);
    Door.setTypeface(tf);
    EdgeBand.setTypeface(tf);
    ModFur.setTypeface(tf);

   /* Particle.startAnimation(animScale);
    MDF.startAnimation(animScale);
    Laminates.startAnimation(animScale);
    Ply.startAnimation(animScale);
    Floor.startAnimation(animScale);
    Door.startAnimation(animScale);
    EdgeBand.startAnimation(animScale);
    ModFur.startAnimation(animScale); */


    Particle.setOnClickListener(Par);

}


private View.OnClickListener Par = new View.OnClickListener(){
    public void onClick(View …
Run Code Online (Sandbox Code Playgroud)

android android-xml

-1
推荐指数
1
解决办法
117
查看次数

如何从strings.xml中的字符串数组中获取字符串

是否可以从xml文件中的字符串数组中获取字符串? 我需要一个字符串而不是字符串数组:)

strings.xml中

<string-array name="link_categories">
    <item>http://google.com</item>
    <item>http://yahoo.com</item>
  </string-array>
Run Code Online (Sandbox Code Playgroud)

Brabra.java

 WebPageCurrent = getResources().getString(get string from string array);
Run Code Online (Sandbox Code Playgroud)

android android-xml

-1
推荐指数
1
解决办法
5931
查看次数

无法弄清楚为什么scrollview不滚动

我正在制作一个简单的转换器应用程序.尝试转换输入并在下面的EditTexts中显示它,但我的ScrollView不起作用.(字面意思什么也没做)我使用ConstraintLayout作为root,我在其中有LinearLayout,它是ScrollView的根.

那么,我在这里错过了什么?

布局的图像

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="gns.converter.LengthConversion">

    <Spinner
        android:id="@+id/spinnerTo"
        android:layout_width="120dp"
        android:entries="@array/spinnerLengthItems"
        android:layout_height="wrap_content"
        app:layout_constraintLeft_toRightOf="@+id/textFrom"
        android:layout_marginLeft="42dp"
        app:layout_constraintBaseline_toBaselineOf="@+id/textFrom"
        android:layout_marginStart="42dp" />

    <EditText
        android:id="@+id/textFrom"
        android:layout_width="150dp"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="number"
        android:textSize="20sp"
        android:hint="(From) 0"
        android:gravity="right"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_marginTop="44dp"
        android:layout_marginLeft="16dp"
        app:layout_constraintLeft_toLeftOf="parent"
        android:layout_marginStart="16dp" />


    <Button
        android:id="@+id/buttonConvert"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="78dp"
        android:layout_marginTop="13dp"
        android:text="CONVERT"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textFrom"
        android:layout_marginStart="78dp" />

    <Button
        android:id="@+id/buttonClear"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="42dp"
        android:layout_marginTop="23dp"
        android:text="CLEAR"
        app:layout_constraintLeft_toRightOf="@+id/buttonConvert"
        app:layout_constraintTop_toBottomOf="@+id/spinnerTo"
        android:layout_marginStart="42dp" />

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="495dp"
        android:orientation="horizontal"
        android:layout_marginRight="8dp"
        android:background="#e40707"
        app:layout_constraintRight_toRightOf="parent"
        android:layout_marginLeft="8dp"
        app:layout_constraintLeft_toLeftOf="parent"
        android:layout_marginTop="30dp"
        app:layout_constraintTop_toBottomOf="@+id/buttonConvert"
        app:layout_constraintHorizontal_bias="0.0">


        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="fill_parent"
            >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"> …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-xml android-scrollview

-1
推荐指数
1
解决办法
2432
查看次数

在 LinearLayout 中将文本视图左对齐(水平)

我试图让我的Textview左对齐已经尝试过。但android:gravity="left"什么也没发生。

这是我的 XML 代码:

  <LinearLayout
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:orientation="horizontal">
         <TextView
          android:id="@+id/textView11"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_margin="10dp"
          android:layout_weight="1"
          android:text="Email:"
          android:textSize="20dp"/>
        <EditText
          android:id="@+id/editTextAddress"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_margin="10dp"
          android:layout_weight="1"
          android:background="@drawable/bg"
          android:hint="Enter Address"/>
  </LinearLayout>
Run Code Online (Sandbox Code Playgroud)

java xml android android-layout android-xml

-1
推荐指数
1
解决办法
724
查看次数

以编程方式获取 edittext 视图的 ID?

这是我的 Edittext 的 XML 代码,我用这个名称ettMId设置了 id

                <EditText
                android:id="@+id/ettMId"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/login_hint_email_id"
                android:imeOptions="actionNext"
                android:inputType="text|textEmailAddress"
                android:nextFocusDown="@id/etLPassword"
                android:singleLine="true"
                android:theme="@style/AppEditTextStyle" />
Run Code Online (Sandbox Code Playgroud)

我希望在我的活动类中以编程方式获得该 ID。

我尝试使用这段代码来获取 id

   int id=ettMId.getId();
Run Code Online (Sandbox Code Playgroud)

但我得到了以下结果

 If2131230797
Run Code Online (Sandbox Code Playgroud)

实际上我想要与我在 XML 中设置的相同的 id 名称(ettMId )

android android-xml android-edittext android-studio

-1
推荐指数
1
解决办法
773
查看次数

添加一条水平线和一些底部带有文本的图标,如 facebook

我想在卡片视图中添加页脚。

我当前在 RecyclerView 中的 XML 布局是这样的:

(此 xml 代码充当 RecyclerView 中的行)

代码:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <android.support.v7.widget.CardView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"

        android:layout_margin="@dimen/activity_margin_half"
        app:cardBackgroundColor="@color/placeholder_grey"
        app:cardCornerRadius="6dp"
        app:cardPreventCornerOverlap="false">

        <ProgressBar
            android:id="@+id/movie_progress"
            style="@style/Widget.AppCompat.ProgressBar"
            android:layout_width="@dimen/activity_margin"
            android:layout_height="@dimen/activity_margin"
            android:layout_gravity="center"
            android:theme="@style/CircularProgress"/>

        <ImageView
            android:id="@+id/movie_poster"
            android:layout_width="@dimen/poster_thumb_width"
            android:layout_height="@dimen/poster_thumb_height"/>



    </android.support.v7.widget.CardView>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="bottom"
        android:layout_marginTop="@dimen/activity_margin"
        android:background="@drawable/bg_round_rect"
        android:orientation="vertical"
        android:paddingBottom="@dimen/activity_margin"
        android:paddingEnd="@dimen/activity_margin"
        android:paddingLeft="@dimen/poster_thumb_width"
        android:paddingRight="@dimen/activity_margin"
        android:paddingStart="@dimen/poster_thumb_width"
        android:paddingTop="@dimen/activity_margin_half">

        <TextView
            android:id="@+id/movie_year"
            style="@style/TextAppearance.AppCompat.Caption"

            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/activity_margin_content"
            android:layout_marginStart="@dimen/activity_margin_content"

            android:alpha="0.38"
            android:gravity="start"
            android:maxLines="1"
            android:textStyle="bold"
            android:textColor="#f14e4e"
            tools:text="2009 | EN"/>

        <TextView
            android:id="@+id/movie_title"
            style="@style/TextAppearance.AppCompat.Subhead"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/activity_margin_content"
            android:layout_marginStart="@dimen/activity_margin_content"
            android:layout_marginTop="@dimen/activity_margin_quarter"
            android:textColor="#9b92b3"
            android:maxLines="1" …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-xml android-cardview

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

Android Circle Button有4条纹

我正在尝试在Android中创建一个包含4条斜条纹的圆形按钮.

像这样

(抱歉我的照片编辑技巧很差.

圆圈应该是满的,不要如图所示切断.

试图使用图层列表并添加了背景按钮不起作用.

知道怎么做吗?

android android-layout android-xml

-3
推荐指数
1
解决办法
485
查看次数

onClickListener vs onClick()

如果我们呼吁双方onClickListeneronClick()从XML的方法,则始终onClickListener方法被调用.
为什么会这样?

public class MainActivity extends Activity {
Button buttonCheck;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    buttonCheck = (Button) findViewById(R.id.buttonTesting);
    buttonCheck.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Toast.makeText(getApplicationContext(), "On Click Listener", Toast.LENGTH_SHORT).show();
            Log.e("OnClick", "Called");
        }
    });
}
public void checkStatus(View view) {
    Toast.makeText(getApplicationContext(), "On checkStatus", Toast.LENGTH_SHORT).show();
    Log.e("checkStatus", "Called");
}

}
Run Code Online (Sandbox Code Playgroud)

xml布局:

    <Button
    android:id="@+id/buttonTesting"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="162dp"
    android:onClick="checkStatus"
    android:text="Check" />
Run Code Online (Sandbox Code Playgroud)

android onclick android-xml onclicklistener

-6
推荐指数
1
解决办法
844
查看次数