在Android Studio中使用style.xml删除alertDialog的标题

时间:2018-03-17 13:00:09

标签: java android android-studio android-studio-3.0

enter image description here

我想删除"禁忌",这是我的alertDialog的标题!! 我该怎么办? 另外,你能否给出一个扩大alertDialog大小的小贴士?

这是我的style.xml

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

<style name="ActivityTheme" parent="Theme.AppCompat.Light.Dialog">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowActionBar">false</item>
</style>

这是我的manifest.xml

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

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity
        android:name=".MainActivity"
        android:configChanges="orientation|screenSize|keyboardHidden"
        android:screenOrientation="landscape">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".SettingActivity"
        android:theme="@style/ActivityTheme">
    </activity>
</application>

这是我的MainActivity.java代码

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


    ListView listView = findViewById(R.id.listView);
    adapter = new MenuAdapter();

    adapter.addItem(new ItemsOfMenu(R.drawable.home,"Home"));
    adapter.addItem(new ItemsOfMenu(R.drawable.drawer,"All"));
    adapter.addItem(new ItemsOfMenu(R.drawable.star,"Favorite"));
    adapter.addItem(new ItemsOfMenu(R.drawable.megaphone,"New"));
    adapter.addItem(new ItemsOfMenu(R.drawable.plus,"Custom"));
    adapter.addItem(new ItemsOfMenu(R.drawable.settings,"Settings"));
    adapter.addItem(new ItemsOfMenu(R.drawable.shop,"Store"));

    listView.setAdapter(adapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            selectedItem = position;
            adapter.notifyDataSetChanged();

            if(position == 5){

                Intent intent = new Intent(getApplicationContext(),SettingActivity.class);
                startActivityForResult(intent,101);

            }
        }
    });

    GridView gridView = findViewById(R.id.gridView);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
        if(requestCode ==101 && resultCode == RESULT_OK){

        }
}

class MenuAdapter extends BaseAdapter{
    ArrayList<ItemsOfMenu> items = new ArrayList<>();

    @Override
    public int getCount() {
        return items.size();
    }

    public void addItem(ItemsOfMenu item){
        items.add(item);
    }

    @Override
    public Object getItem(int position) {
        return items.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MenuListView view;
        if(convertView == null)
            view = new MenuListView(getApplicationContext());
        else view = (MenuListView) convertView;

        if(position == selectedItem){
            view.setBackgroundColor(Color.WHITE);
        } else view.setBackgroundColor(Color.parseColor("#e0e0e0"));

        view.setImageView(items.get(position).getResId());
        view.setTextView(items.get(position).getMenu());

        return view;
    }
}

}

1 个答案:

答案 0 :(得分:0)

can be changed by adding a whole new style e.g/...
<style name="CustomAlertDialog" parent="android:Theme.Dialog.Alert">
  <item name="android:windowBackground">@drawable/color_panel_background</item><!-- Used for the buttons -->
    <item name="colorAccent">@color/colorAccent</item>
    <!-- Used for the title and text -->
    <item name="android:textColorPrimary">#FFFFFF</item>
    <!-- Used for the background -->
    <item name="android:background">@color/teal</item>
 </style>
and while initalizing also initialize this theme using ContextThemeWrapper